公司内网的一些服务器宕机或者出问题时,网络管理人员不能及时发现,利用sendmail+shell脚本可以及时告知网络管理人员。
其中iplist.txt文件为监控的服务器ip地址列表。
1
2
3
4
|
[root@mail sh]
# cat iplist.txt
192.168.1.1
192.168.1.100
192.168.1.200
|
查看脚本:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@mail sh]
# cat check_ip_all.sh
#!/bin/bash
BASE=
/root/sh
for
ip
in
`
cat
$BASE
/iplist
.txt`
do
ping
$ip -c 2 >
/dev/null
2>&1
if
[ ! $? -
eq
0 ];
then
echo
"The company server $ip down,please solved the problem as soon as possible!"
>
/root/sh/mail
.txt
mail -s
"The server $ip is down now"
shifeng_zhang88@163.com <
/root/sh/mail
.txt
fi
done
#添加crontab,每2分钟自动检测
*
/5
* * * *
/bin/bash
/root/sh/check_ip_all
.sh >
/dev/null
2>&1
|
本文转自 sfzhang 51CTO博客,原文链接:http://blog.51cto.com/sfzhang88/857716,如需转载请自行联系原作者