1
2
3
|
# yum -y install sendmail
# /etc/init.d/sendmail start
# chkconfig sendmail on
|
1
|
# yum -y install mutt
|
1
2
3
4
5
6
7
|
# vim /etc/Muttrc
set
charset=
"utf-8"
#设置发邮件编码
set
envelope_from=
yes
set
rfc2047_parameters=
yes
#解决附件乱码问题
set
realname=
"报警"
#发件人别名
set
use_from=
yes
#指定是否显示别名
set
from=monitor@
test
.com
#发送人地址
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
#!/bin/bash
DATE=`
date
+%F
" "
%H:%M`
IP=
/root/monitor/ip
.txt
#ip地址表
MAIL=zhenliang369@163.com
for
ip
in
$(
cat
$IP |
sed
'/^#/d'
)
do
for
((i=1;i<=3;i++))
do
ping
-c 1 $ip &>
/dev/null
[ $? -
ne
0 ] &&
let
FailCount+=1;
done
done
[ -z $FailCount ] && FailCount=0
#当ping都正常时,FailCount值为空,就设置FailCount值为0,用整数比较
if
[ $FailCount -
eq
2 ];
then
#echo "$IP ping is failed."
echo
-e
"Date : $DATE\nHost : $ip\nProblem : Ping is failed, Please check ! ! !"
| mutt -s
"Ping Monitor"
$MAIL
fi
|
1
|
done
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
#!/bin/bash
MAIL=
"baojingtongzhi@163.com huangxiaohong@loongtao.com"
for
ip
in
$(
cat
ip_list|
sed
"/^#/d"
) #ip_list是当前目录下IP表
do
ping
-c 1 $ip &>
/dev/null
#三个ping有一个能通,说明服务器正常
a=$?
sleep
2
ping
-c 1 $ip &>
/dev/null
b=$?
sleep
2
ping
-c 1 $ip &>
/dev/null
c=$?
sleep
2
DATE=$(
date
+%F
" "
%H:%M)
if
[ $a -
ne
0 -a $b -
ne
0 -a $c -
ne
0 ];
then
echo
-e
"Date : $DATE\nHost : $ip\nProblem : Ping is failed."
| mail -s
"Ping $ip failed From 255.252"
$MAIL
#else
# echo "$ip ping is successful."
fi
done
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
#!/bin/bash
while
true
do
DATE=`
date
+%F
" "
%H:%M`
MAIL=
"zhenliang369@163.com"
for
ip
in
$(
cat
ip_list|
sed
"/^#/d"
) #ip_list是当前目录下IP表
do
num=$(
ping
-c 2 $ip |
grep
"100% packet loss"
|
wc
-l)
if
[ $num == 1 ];
then
echo
-e
"Date : $DATE\nHost : $i\nProblem : Ping is failed."
| mail -s
"Ping $i failed From 255.252"
$MAIL
fi
done
sleep
30
done
|