---
title: "09、主要服务可用性监控 (一)"
author: "restart1107"
date: "2011-05-13T13:41:09Z"
tags: ["Python", "Web", "XML", "电信", "脚本"]
categories: ["操作系统"]
slug: "09"
draft: false
lastmod: "2011-06-13T23:28:13Z"
id: 1042404
url: "https://restart1107.iteye.com/blog/1042404"
---

1、方案：

```
1）一套代码与配置，各IDC通过调用脚本参数不同进行区分，每10分钟轮询一次服务。
2）各IDC配置文件间隔7分钟从30.9机器上定时取一次。
```

 

2、xml文档属性值：

```
属性：Service，ServerIp，Port，UrlName，UrlValue，Des，MonitoryPoint，IsAlert
port 端口探测用 nmap来实现，url探测用curl/wget来实现
```

3、项目各文件说明：

```
download服务目录：  /infowarelab/moodle/etraining/download
conference。xml
（1）web站点监控
（2）gc/infosvr 外网只监控443，80端口（除美国外，该IDC只监控443）；
（3）增加。com邮箱服务器110，25端口监控；
（4）增加box 杭州，深圳infosvr监控，深圳监控8000端口状态，杭州监控4000，8000，9000端口状态，北京监控80，443端口状态；

pso.xml
（1）增加。cn邮箱服务器110，25端口监控和url监控；

rtothers。xml
（1）增加Red5 domain service信息；
（2）修改有关SIPProxy的备注信息；
（3）因CTI,只允许杭州及北京IDC访问，去除easycall-cti.infowarelab.cn，60.12.234.21 443端口监控；
（4）因网通访问正常，其他电信等访问不了，去除http://download-xs.infowarelab.cn/download监控
```

 

2、部分语法说明：

```
1、信息块用“|”隔开
        cat errinfo.log|sed 's/|/\<\/td\>\<td\>/g'|sed -e 's/$/\<\/td\>\<\/tr\>\<tr\>\<td\>/'|tr -s "\n" " "|tr -s "\r" " ">b.log  
2、wget超时与尝试次数设置 //尝试3次，每次时间为1s
        time wget -T 1 -t 3 http://10.0.1.23
3、grep精确匹配，-w， --word-regexp； -x, --line-regexp
         grep -w 431
   逻辑或 grep -E "aaa|bbb"
3、假设目标机器为存活状态，在固定时间内只扫描存活的端口
        nmap  -P0 -p80,113 -host_timeout 45000  59.151.25.148 
4、本该四行没有分行，全部堆在一行，这是为什么，如何让它换行？加双引号让变量换行
        temp=`/usr/bin/nmap  -P0 -p80,443 -host_timeout 45000  59.151.25.148|grep open `
        echo "${temp}"|wc -l
5、字符串转为数组
str2="a#b#c"
a=($(echo $str2 | tr '#' ' ' | tr -s ' '))
length=${#a[@]}
for ((i=0; i<$length; i++))
do
    echo ${a[$i]}
done
#echo ${a[2]}
6、多行字符串逐行读入处理：把多行字符串当成读取文件后的内容；
7、字符串全文查找替换：用sed，或tr（下拉符用空格替换）
        echo "t,xx,t" |sed 's/,/|/g'
        tr '_' " " 
8、yum update 时出现python目录依赖出错的解决办法
          yum clean all
          yum -y update
9、定时下载脚本，需要指明下载地址：
        cd ${ConfigDir}
       lcd ${CurDir}
    10、判断字符串是否为空
        if [ "$variable" ]; then
           echo "非空"
        else
            echo "空"
        fi
     11、缺少参数，退出shell 
        LogFile=$6
                if [  -z ${LogFile} ];then
                 echo "The lack of parameters, exit checkport"
                 exit
        fi
```