2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
| #!/bin/bash
#auto monitor
#write by 2015-8-9
IP=ifconfig |grep "Bcast" |awk '{print $2}'|sed 's/addr://g'
DATE=`date`
EMAIL=email.txt
cat << EOF
########################################################
######## wlecome to use auto ###########
######## monitor scripts ###########
########################################################
EOF
if [ -z $1 ];then
echo -e "\033[32mUsage :{sh $0 nginx|http|mysql|ntp|list.txt}\033[0m"
sleep 2
exit
fi
if [ -f "$1" -a "$1" == "list.txt" ];then
for i in `cat list.txt`
do
count=`ps -ef |grep $i|grep -v grep|grep -v "$0"|wc -l`
if [ $count -eq 0 ];then
cat >$EMAIL << EOF
+++++++++++++++++++SERVER MONITOR++++++++++++++++++++++++
通知类型:故障
服务:$i
主机:$IP
状态:警告
日期:$DATE
额外信息:
CRITTACL + $i server is no running ,please check..
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
EOF
echo -e "\033[32mthe monitor $i warning ,please check..\033[0m"
mail -s "$IP $i warning" 752840649@qq.com < $EMAIL >>/dev/null 2>&1
else
echo -e "\033[32mthe monitor $i is ok...\033[0m"
fi
done
else
count=`ps -ef |grep $1|grep -v grep|grep -v $0|wc -l`
if [ $count -eq 0 ];then
cat >$EMAIL << EOF
+++++++++++++++++++SERVER MONITOR++++++++++++++++++++++++
通知类型:故障
服务:$1
主机:$IP
状态:警告
日期:$DATE
额外信息:
CRITTACL + $1 server is no running ,please check..
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
EOF
dos2unix $EMAIL
echo -e "\033[32mthe monitor $1 warning ,please check..\033[0m"
mail -s "$IP $1 warning" 752840649@qq.com < $EMAIL >>/dev/null 2>&1
else
echo -e "\033[32mthe monitor $1 is ok...\033[0m"
fi
fi
|