公司内网的一些服务器宕机或者出问题时,网络管理人员不能及时发现,利用sendmail+shell脚本可以及时告知网络管理人员。
其中iplist.txt文件为监控的服务器ip地址列表。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 1[root@mail sh]# cat iplist.txt
2
3
4
5
6192.168.1.1
7
8
9
10192.168.1.100
11
12
13
14192.168.1.200
15
查看脚本:
1
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
63
64
65
66 1[root@mail sh]# cat check_ip_all.sh
2
3
4
5
6#!/bin/bash
7
8
9
10
11BASE=/root/sh
12
13
14
15
16
17for ip in `cat $BASE/iplist.txt`
18
19
20
21
22do
23
24
25
26
27ping $ip -c 2 > /dev/null 2>&1
28
29
30
31
32
33 if [ ! $? -eq 0 ];then
34
35
36
37
38
39 echo "The company server $ip down,please solved the problem as soon as possible!" > /root/sh/mail.txt
40
41
42
43
44
45 mail -s "The server $ip is down now" shifeng_zhang88@163.com < /root/sh/mail.txt
46
47
48
49
50
51 fi
52
53
54
55
56done
57
58
59
60#添加crontab,每2分钟自动检测
61
62
63
64
65*/5 * * * * /bin/bash /root/sh/check_ip_all.sh > /dev/null 2>&1
66
本文转自 sfzhang 51CTO博客,原文链接:http://blog.51cto.com/sfzhang88/857716,如需转载请自行联系原作者