设计一个脚本,监控远程的一台机器(假设ip为123.23.11.21)的存活状态,当发现宕机时发一封邮件给你自己。
提示:
1. 你可以使用ping命令 ping -c10 www.baidu.com
2. 发邮件的命令是 echo "邮件内容" |mail -s "主题" abc@139.com
3. 脚本可以搞成死循环,每隔30s检测一次
提示:
1. 你可以使用ping命令 ping -c10 www.baidu.com
2. 发邮件的命令是 echo "邮件内容" |mail -s "主题" abc@139.com
3. 脚本可以搞成死循环,每隔30s检测一次
0
#!bin/bash
#设计一个脚本,监控远程的一台机器(假设ip为123.23.11.21)的存活状态,当发现宕机时>发一封邮件给你自己。
#ipaddr
ip=123.23.11.21
#mail
ma=abc@139.com
while :;do
pa=`ping -c5 $ip|grep 'receive'|awk -F ',' '{print $2}'|awk '{print $1}'`
if [ $pa=="0" ];then
echo "The host $ip is die"|mail -s "message" $ma
fi
sleep 30
done
#设计一个脚本,监控远程的一台机器(假设ip为123.23.11.21)的存活状态,当发现宕机时>发一封邮件给你自己。
#ipaddr
ip=123.23.11.21
ma=abc@139.com
while :;do
pa=`ping -c5 $ip|grep 'receive'|awk -F ',' '{print $2}'|awk '{print $1}'`
if [ $pa=="0" ];then
echo "The host $ip is die"|mail -s "message" $ma
fi
sleep 30
done
0
#!/bin/bash
#检查宕机
#20130927
while :;do
ping -c10 123.23.11.21>/dev/dull
if($?!=0)
then
echo "邮件内容" |mail -s "主题" abc@139.com
fi
sleep 30
done
#检查宕机
#20130927
while :;do
ping -c10 123.23.11.21>/dev/dull
if($?!=0)
then
echo "邮件内容" |mail -s "主题" abc@139.com
fi
sleep 30
done
0
本帖最后由 地平线 于 2013-9-27 15:15 编辑
#!/bin/bash
ip='123.23.11.21'
while true
do
sleep 30
ping -c 10 $ip
if [[ $? == 0 ]];then
:
else
echo "$ip" |mail -s "error" abc@139.com
fi
done
#!/bin/bash
ip='123.23.11.21'
while true
do
sleep 30
ping -c 10 $ip
if [[ $? == 0 ]];then
:
else
echo "$ip" |mail -s "error" abc@139.com
fi
done
0
# bin/bash
while : ; do
ping -c10 www.baidu.com > 1.txt
if [ -z 1.txt ] ;then echo "dangji" |mail -s "baidudangji" abc@139.com
fi
sleep 30
done
while : ; do
ping -c10 www.baidu.com > 1.txt
if [ -z 1.txt ] ;then echo "dangji" |mail -s "baidudangji" abc@139.com
fi
sleep 30
done
0
#!/bin/bsah
ip="123.23.11.21"
ping -c 4 $ip >/dev/null
a=$?
while : ;do
if [ $a -ne 0 ];then
echo "$ip is not alive" |mail -s "test" 123@139.com
fi
sleep 30
done
ip="123.23.11.21"
ping -c 4 $ip >/dev/null
a=$?
while : ;do
if [ $a -ne 0 ];then
echo "$ip is not alive" |mail -s "test" 123@139.com
fi
sleep 30
done
0
#!/bin/bash
while :; do
if `ping -c 10 www.baidu.com>/dev/null 2>&1`;then
echo "ok" >/dev/null
else
echo "down" | mail -s baojing 891287870@qq.com
sleep 30
fi
done
while :; do
if `ping -c 10 www.baidu.com>/dev/null 2>&1`;then
echo "ok" >/dev/null
else
echo "down" | mail -s baojing 891287870@qq.com
sleep 30
fi
done
0
[root@OceanV sh]# cat check_ping.sh
#!/bin/bash
IP=192.168.9.99
while true
do
ping -c 10 $IP > /dev/null
if [ $? -eq 0 ]
then
echo "`date +%F-%H:%M:%S` $IP is OPEN" >> /root/sh/check_ping.log
else
echo "`date +%F-%H:%M:%S` $IP is CLOSE" |mail -s "check_ping" root@localhost
echo "`date +%F-%H:%M:%S` $IP is CLOSE" >> /root/sh/check_ping.log
fi
sleep 30
done
#!/bin/bash
IP=192.168.9.99
while true
do
ping -c 10 $IP > /dev/null
if [ $? -eq 0 ]
then
echo "`date +%F-%H:%M:%S` $IP is OPEN" >> /root/sh/check_ping.log
else
echo "`date +%F-%H:%M:%S` $IP is CLOSE" |mail -s "check_ping" root@localhost
echo "`date +%F-%H:%M:%S` $IP is CLOSE" >> /root/sh/check_ping.log
fi
sleep 30
done
0
#!/bin/bash
##通过ping查看一台机器是否存活,说过没有存活则发送邮件!
while :;
do
ping -c10 www.baidu.com
if [ `echo $?` -eq '0' ];then
sleep 10
else
echo "zhe jiqi is down!" |mail -s "DOWN" lichao@jiangmin.com
fi
done
##通过ping查看一台机器是否存活,说过没有存活则发送邮件!
while :;
do
ping -c10 www.baidu.com
if [ `echo $?` -eq '0' ];then
sleep 10
else
echo "zhe jiqi is down!" |mail -s "DOWN" lichao@jiangmin.com
fi
done
0
#!/bin/bash
while true
do
num=`ping 192.168.2.205 -c 10 | grep "packet loss" | awk '{print $6}' | awk -F "%" '{print $1}'`
if [ $num -eq 0 ];then
echo "the server is not alive" | mail -s "the server is down" zyfeifei@139.com
fi
sleep 30
done
while true
do
num=`ping 192.168.2.205 -c 10 | grep "packet loss" | awk '{print $6}' | awk -F "%" '{print $1}'`
if [ $num -eq 0 ];then
echo "the server is not alive" | mail -s "the server is down" zyfeifei@139.com
fi
sleep 30
done
0
#!/bin/bash
## This script is for ping to check a remote machine if alive.
## Writed by Louis on 2014/08/29 17:00
while :;do
echo `ping -c10 www.baidu.com > ping.log`
ping=`grep '100% packet loss' ping.log|awk -F ',' '{print $3}'|awk '{print $1}'`
if [ ! -z $ping ]; then
echo "www.baidu.com is time out!"|mail -s "Ping check" root@localhost
fi
sleep 30
done
## This script is for ping to check a remote machine if alive.
## Writed by Louis on 2014/08/29 17:00
while :;do
echo `ping -c10 www.baidu.com > ping.log`
ping=`grep '100% packet loss' ping.log|awk -F ',' '{print $3}'|awk '{print $1}'`
if [ ! -z $ping ]; then
echo "www.baidu.com is time out!"|mail -s "Ping check" root@localhost
fi
sleep 30
done
0
本帖最后由 游夜 于 2014-9-4 22:58 编辑
#!/bin/bash
while :;doping -c10 www.baidu.com
if [ echo $? -ne 0 ];then
echo "Your Website www.baidu.com is down.Please check it"|mail -s "Website Down" 275235245@qq.com
fi
sleep 30
done
#!/bin/bash
while :;doping -c10 www.baidu.com
if [ echo $? -ne 0 ];then
echo "Your Website www.baidu.com is down.Please check it"|mail -s "Website Down" 275235245@qq.com
fi
sleep 30
done
0
#! /bin/bash
n=`ping -c10 123.23.11.21|wc -l`
while :; do
if [ $n -gt 10 ]; then
echo "The network is connected"
else
echo "This machine is down" |mail -s "outage" abc@139.com
fi
sleep 30
done
n=`ping -c10 123.23.11.21|wc -l`
while :; do
if [ $n -gt 10 ]; then
echo "The network is connected"
else
echo "This machine is down" |mail -s "outage" abc@139.com
fi
sleep 30
done
0
#!/bin/bash
while sleep 30
do
rec=`ping -c10 123.23.11.21 | grep 64`
if [ -z $rec ]
then
echo "21 is down" | mail -s "Alarm" abc@139.com 2>log
else
echo "21 is up" > log
fi
done
while sleep 30
do
rec=`ping -c10 123.23.11.21 | grep 64`
if [ -z $rec ]
then
echo "21 is down" | mail -s "Alarm" abc@139.com 2>log
else
echo "21 is up" > log
fi
done
0
cat check_active.sh
#!/bin/bash
# Desc: this scripts is to check host staus , if host has downed then send mail to the user;
# Author: Jeffery.Su
# Date: 9/9/2014
# version: V1
IP_ADDR=`ifconfig -a | grep "inet addr"| awk '{print $2}'|awk -F: '{print $2}'|head -1`
while :;
do
NET_ACTIVE=` ping -c3 $IP_ADDR| grep received|awk -F"," '{print $2}'|awk '{print $1}' `
if [ $NET_ACTIVE == 0 ];
then
echo "Host $IP_ADDR is down"|mail -s "Host $IP_ADDR is down" 781303205@qq.com
else
echo "The host is active"
fi
sleep 10;
done{:5_121:}
#!/bin/bash
# Desc: this scripts is to check host staus , if host has downed then send mail to the user;
# Author: Jeffery.Su
# Date: 9/9/2014
# version: V1
IP_ADDR=`ifconfig -a | grep "inet addr"| awk '{print $2}'|awk -F: '{print $2}'|head -1`
while :;
do
NET_ACTIVE=` ping -c3 $IP_ADDR| grep received|awk -F"," '{print $2}'|awk '{print $1}' `
if [ $NET_ACTIVE == 0 ];
then
echo "Host $IP_ADDR is down"|mail -s "Host $IP_ADDR is down" 781303205@qq.com
else
echo "The host is active"
fi
sleep 10;
done{:5_121:}
0
#!/bin/bash
while :
do
sleep 30
ping -c5 123.23.11.21
if [ $? -eq 0 ] ;then
echo "host is up"
else
echo "host is down" |mail -s "ping" abc@139.com
fi
done
while :
do
sleep 30
ping -c5 123.23.11.21
if [ $? -eq 0 ] ;then
echo "host is up"
else
echo "host is down" |mail -s "ping" abc@139.com
fi
done
0
本帖最后由 王靖 于 2014-11-22 17:19 编辑
#! /bin/bash while : ;do
/bin/ping -c 1 -W 1 www.baidu.com &>/dev/null
if [ $? -ne 0 ] ;then
echo "www.baidu.com down" | mail -s "host donw" abc@139.com
fi
sleep 2
done
#! /bin/bash while : ;do
/bin/ping -c 1 -W 1 www.baidu.com &>/dev/null
if [ $? -ne 0 ] ;then
echo "www.baidu.com down" | mail -s "host donw" abc@139.com
fi
sleep 2
done
0
- #!/bin/bash
- # The monitoring host survival script.
- # Writen by Wangxiaoqiang 2014-11-24.
- HOST=xxx.xxx.x.xx
- MAIL=xxxxxxxxxxx@xxx.com
- while true
- do
- ping -c 10 $HOST > /dev/null
- if [ $? -ne 0 ]
- then
- echo "HOST:$HOST down." | mail -s "MAIL FOR $HOSTNAME" $MAIL
- fi
- sleep 30
- done
- # End
0
#!/bin/bash
ip="123.23.11.21"
while :
do
ping -c10 $ip
if [[ $? != 0 ]]
then
echo "$ip is dead" | mail -s "$ip is dead" abc@139.com
fi
sleep 30
done
ip="123.23.11.21"
while :
do
ping -c10 $ip
if [[ $? != 0 ]]
then
echo "$ip is dead" | mail -s "$ip is dead" abc@139.com
fi
sleep 30
done
0
#!/bin/bash #author: GY #date:2014-11-29 while :; do ping -c 10 192.168.0.99 if [ `echo $?` -eq 0 ];then sleep 30 else echo "192.168.0.99 is shutdown!" | mail -s "shutdown" 445043972@qq.com sleep 5 break fi done
0
#!/bin/bash
#author: GY
#date:2014-11-29
while :; do
ping -c 10 192.168.0.99
if [ `echo $?` -eq 0 ];then
sleep 30
else
echo "192.168.0.99 is shutdown!" | mail -s "shutdown" 445043972@qq.com
sleep 5
break
fi
done
刚才是快速回复,格式全乱了。现重新发表回复
#!/bin/bash
#author: GY
#date:2014-11-29
while :; do
ping -c 10 192.168.0.99
if [ `echo $?` -eq 0 ];then
sleep 30
else
echo "192.168.0.99 is shutdown!" | mail -s "shutdown" 445043972@qq.com
sleep 5
break
fi
done
刚才是快速回复,格式全乱了。现重新发表回复
0
本帖最后由 川娃子在大连 于 2014-12-16 20:50 编辑
#!/bin/bash
# -------------------------------------------------------------------------------
# Filename: amingtest4.sh
# Revision: 1.0
# Date: 2014/12/16
# Author: FUQIANG LI
# Email: 317377106@qq.com
# Notes: aminglinux shell exercises of 2013-09-27
# -------------------------------------------------------------------------------
read -p "Please input a host IP: (end for exit) " hostIP
while :
do
if [ $hostIP == "end" ]
then
exit 0
else
ping -c10 $hostIP &>/dev/null
if [ $? -eq 0 ]
then
echo "the hostIP $hostIP is up!"
else
echo "the hostIP $hostIP is down!"| tee warming.log |mail -s "warming" 317377106@qq.com
fi
fi
sleep 30
done
#!/bin/bash
# -------------------------------------------------------------------------------
# Filename: amingtest4.sh
# Revision: 1.0
# Date: 2014/12/16
# Author: FUQIANG LI
# Email: 317377106@qq.com
# Notes: aminglinux shell exercises of 2013-09-27
# -------------------------------------------------------------------------------
read -p "Please input a host IP: (end for exit) " hostIP
while :
do
if [ $hostIP == "end" ]
then
exit 0
else
ping -c10 $hostIP &>/dev/null
if [ $? -eq 0 ]
then
echo "the hostIP $hostIP is up!"
else
echo "the hostIP $hostIP is down!"| tee warming.log |mail -s "warming" 317377106@qq.com
fi
sleep 30
done
0
本帖最后由 川娃子在大连 于 2014-12-17 00:29 编辑
#!/bin/bash
# -------------------------------------------------------------------------------
# Filename: amingtest4.sh
# Revision: 2.0
# Date: 2014/12/17
# Author: FUQIANG LI
# Email: 317377106@qq.com
# Notes: aminglinux shell exercises of 2013-09-27
# -------------------------------------------------------------------------------
read -p "Please input a host IP: (end for exit) " hostIP
while :
do
if [ $hostIP == "end" ]
then
exit 0
elif ping -c5 $hostIP &>/dev/null
then
echo "the hostIP $hostIP is up!"
else
echo "the hostIP $hostIP is down!"|tee ./warming.log|mail -s "warming" 317377106@qq.com < ./warming.log
fi
sleep 30
done
#!/bin/bash
# -------------------------------------------------------------------------------
# Filename: amingtest4.sh
# Revision: 2.0
# Date: 2014/12/17
# Author: FUQIANG LI
# Email: 317377106@qq.com
# Notes: aminglinux shell exercises of 2013-09-27
# -------------------------------------------------------------------------------
read -p "Please input a host IP: (end for exit) " hostIP
while :
do
if [ $hostIP == "end" ]
then
exit 0
elif ping -c5 $hostIP &>/dev/null
then
echo "the hostIP $hostIP is up!"
else
echo "the hostIP $hostIP is down!"|tee ./warming.log|mail -s "warming" 317377106@qq.com < ./warming.log
fi
sleep 30
done
0
#!/bin/bash # Written 2014-12-22 cuizhipeng while true do m=`ping -c10 www.baidu.com | grep 'time out'` if [ -n $m ] then echo "Please up system" fi sleep 30 done
0
本帖最后由 cmzsteven 于 2015-2-7 20:57 编辑
ip=123.23.11.21
while :; do
info=`ping -c10 $ip |grep '100% packet loss'|wc -l`
if (($info==1)); then
echo "Your host is halt! Host IP is $ip" |mail -s "Host is halt" abc@139.com
fi
sleep 30
done
如果不用死循环的话,可以加入到crontab中执行
如果提示:
send-mail: warning: valid_hostname: numeric hostname: 5
send-mail: fatal: file /etc/postfix/main.cf: parameter mydomain: bad parameter value: 5
请安装sendmail
yum install -y sendmail
ip=123.23.11.21
while :; do
info=`ping -c10 $ip |grep '100% packet loss'|wc -l`
if (($info==1)); then
echo "Your host is halt! Host IP is $ip" |mail -s "Host is halt" abc@139.com
fi
sleep 30
done
如果不用死循环的话,可以加入到crontab中执行
如果提示:
send-mail: warning: valid_hostname: numeric hostname: 5
send-mail: fatal: file /etc/postfix/main.cf: parameter mydomain: bad parameter value: 5
请安装sendmail
yum install -y sendmail
0
本帖最后由 wuhen 于 2015-2-18 18:49 编辑
- #!/bin/bash
- while :;
- do
- ip=`ping -c 10 www.baidu.com|grep 'received'|awk '{print $4}'`
- if [ $ip -eq 10 ]
- then
- echo "network normal"
- else
- echo "network abnormal"|mail -s "network flase" abc@139.com
- fi
- sleep 30
- done
0
#!/bin/bash
#
while :; do
ping -c10 123.23.11.21 > /dev/null || mail -s "123.23.11.21 is down" abc@139.com
sleep 30
done
#
while :; do
ping -c10 123.23.11.21 > /dev/null || mail -s "123.23.11.21 is down" abc@139.com
sleep 30
done
0
#!/bin/bash
#
while true
do
ping 192.168.1.108 -c 1 -w 1
if [ $? == 0 ];then
echo "192.168.1.108 is up"
else
echo "wrong ping"|mail -s "wrong ping" root@localhost.localdomain
echo "192.168.1.108 is down"
fi
sleep 30
done
#
while true
do
ping 192.168.1.108 -c 1 -w 1
if [ $? == 0 ];then
echo "192.168.1.108 is up"
else
echo "wrong ping"|mail -s "wrong ping" root@localhost.localdomain
echo "192.168.1.108 is down"
fi
sleep 30
done
0
本帖最后由 sss 于 2015-6-5 15:31 编辑
- #!/bin/bash
- while :
- do
- ping -c 123.23.11.21 >/dev/null 2>&1
- if [ $? != 0 ]
- then
- echo "shutdown shutdown shutdown" | mail -s "123.23.11.21 Downtime" xxxxxxxxxx@qq.com
- fi
- sleep 30
- done
0
#!/bin/bash
while :
do
if p=`ping -c2 123.23.11.2|grep "^[^64]"`
then
echo "网络不通" |mail -s "检查网络" abc@139.com
fi
sleep 30
done
while :
do
if p=`ping -c2 123.23.11.2|grep "^[^64]"`
then
echo "网络不通" |mail -s "检查网络" abc@139.com
fi
sleep 30
done
0
for ip in `cat 4.log` do echo $ip ssh $ip ping -c10 www.daidu.com done echo " ip is $ip service down .please deal with it right now"|mail -s "service is down " 18856066058@139.com
0
这样的思路可行么
- #!/bin/bash
- while :;do
- ping -c5 -w5 61.147.124.57 > /dev/null 2>&1
- if [ $? -ne 0 ];then
- echo "DST WAS DOWN at `date +%T`"
- else
- echo " DST IS ALIVED"
- fi
- sleep 5
- done
这样的思路可行么
0
while :;do
a=`ping -c5 www.baidu.com | grep packet|awk '{print $4}'`
if[$a -eq 0 ];then
echo "邮件内容" |mail -s "主题" abc@139.com
else
sleep 3000
fi
done
a=`ping -c5 www.baidu.com | grep packet|awk '{print $4}'`
if[$a -eq 0 ];then
echo "邮件内容" |mail -s "主题" abc@139.com
else
sleep 3000
fi
done
0
while :
do
ping -c10 www.baidu.com
a=`echo $?`
if [ $a != 0 ]
then
echo "192.168.153.130 ping is down" |mail -s "153.130 is down" 13@mail.com
else
echo "server is up"
fi
sleep 30
done
while :
do
ping -c10 www.baidu.com
a=`echo $?`
if [ $a != 0 ]
then
echo "192.168.153.130 ping is down" |mail -s "153.130 is down" 13@mail.com
else
echo "server is up"
fi
sleep 30
done
0
while : do sleep 30 pinglog=`ping -c10 www.baidu.com|grep '^10'|awk -F',' '{print $1,$2}'|sed 's/[a-z]//g'|sed 's/ /\n/g'|grep '^[0-9]'` echo '$pinglog' for lines in `echo $pinglog` do if [$lines -eq '11'] ; then echo"hello" else echo"ok" fi done done
0
while true
do
ping -c 5 123.23.11.21
a=`echo $?`
if [ $a -ne 0 ];then
echo "problem" |mail -s "ip had problem" wwww@xx.com
fi
sleep 30
done
do
ping -c 5 123.23.11.21
a=`echo $?`
if [ $a -ne 0 ];then
echo "problem" |mail -s "ip had problem" wwww@xx.com
fi
sleep 30
done
0
#!/bin/bash
ping -c 4 192.168.1.1 > /tmp/1.txt
add=`grep 'transmitted' /tmp/1.txt | awk '{print $4}'`
if [ "$add" -ne "4" ]
then
echo "你的服务器挂掉了!!" | mailx -s 'aliyun' yu-yan-good@163.com < /tmp/1.txt
rm -rf /tmp/1.txt
fi
ping -c 4 192.168.1.1 > /tmp/1.txt
add=`grep 'transmitted' /tmp/1.txt | awk '{print $4}'`
if [ "$add" -ne "4" ]
then
echo "你的服务器挂掉了!!" | mailx -s 'aliyun' yu-yan-good@163.com < /tmp/1.txt
rm -rf /tmp/1.txt
fi
0
- #!/bin/bash
- #设计一个脚本,监控远程的一台机器(假设ip为123.23.11.21)的存活状态,当发现宕>机时发一封邮件给你自己。
- #
- #提示:
- #1. 你可以使用ping命令 ping -c10 www.baidu.com
- #2. 发邮件的命令是 echo "邮件内容" |mail -s "主题" abc@139.com
- #3. 脚本可以搞成死循环,每隔30s检测一次
- while :
- do
- n=` ping -c10 www.baidu.com | grep 'received'|awk -F ',' '{print $2}'|awk '{if ($1==0) print "0" ;else print "1"}'`
- if [ $n == 0 ]
- then
- # echo "服务器挂了" | mail -s "检测服务器运行状态" abc@139.com
- echo "服务器挂了"
- else
- echo "服务器正常运行"
- fi
- sleep 30s
- done
0
本帖最后由 hlymlv 于 2016-1-7 14:14 编辑
#!/bin/bash
while :
do
ping -c10 123.23.11.21 > /dev/null
if [ $? -ne 0 ];then
echo "bad" |mail -s "linux" abc@139.com
fi
sleep 30
done
这样行吗 ?
#!/bin/bash
while :
do
ping -c10 123.23.11.21 > /dev/null
if [ $? -ne 0 ];then
echo "bad" |mail -s "linux" abc@139.com
fi
sleep 30
done
这样行吗 ?
0
#! /bin/bash while :;do m=`ping -c10 www.baidu.com | wc -l`; if [ $m -eq 15 ] then echo "the PC is shutdown" | mail -s "tixing" 984053525@qq.com fi done else sleep 30
0
#! /bin/bash while :;do m=`ping -c10 www.baidu.com | wc -l`; if [ $m -eq 15 ] then echo "the PC is shutdown" | mail -s "tixing" 984053525@qq.com fi done else sleep 30
0
#! /bin/bash while :;do m=`ping -c10 www.baidu.com | wc -l`; if [ $m -eq 15 ] then echo "the PC is shutdown" | mail -s "tixing" 984053525@qq.com fi done else sleep 30 #没有做好
0
本帖最后由 HMOM 于 2016-1-8 00:17 编辑
ip=11.11.11.11
ping $ip -c10
if [ $? eq 0 ];then
echo "ok" &>/dev/null
else
echo "your webserver is down!!" | mail -s "warning"
123@qq.com
fi
sleep 30
ip=11.11.11.11
ping $ip -c10
if [ $? eq 0 ];then
echo "ok" &>/dev/null
else
echo "your webserver is down!!" | mail -s "warning"
123@qq.com
fi
sleep 30
0
#!/bin/bash
## 监控主机存活状态
i=`ping -c10 172.28.68.31 |grep 'packets' |awk 'OFS=" [ ]+" {print $6}' |sed 's/%//g'`
if [ $i -gt 0 ]
then
ping -c10 172.28.68.31 > /root/1.txt
cat /root/1.txt |mail -s "The server was died! HaHa" xm.cheng@sunmedia.com.cn
fi
## 监控主机存活状态
i=`ping -c10 172.28.68.31 |grep 'packets' |awk 'OFS=" [ ]+" {print $6}' |sed 's/%//g'`
if [ $i -gt 0 ]
then
ping -c10 172.28.68.31 > /root/1.txt
cat /root/1.txt |mail -s "The server was died! HaHa" xm.cheng@sunmedia.com.cn
fi
0
#!/bin/bash
##监控远程的一台机器(假设ip为123.23.11.21)的存活状态,当发现宕机时发一封邮件给你
##write by 2016-01-08
read -p "please enter a ip address: " ip
if [ -n "$ip" ]&&[ -z `echo "$ip"|tr -d "."|sed 's/[0-9]//g'` ];then
while :;do
##ping -q $a -c 2
if ping $ip -c1|grep -q "ttl=";then
echo -e `date +%F" "%T`"\t$ip is good!"
sleep 10
continue
else
echo "ping [$ip] failed,please check ! "
echo "ping [$ip] failed,please check ! " |mail -s "$ip bad" abc@139.com
exit
fi
done
else
echo "输入值为空或不是正确的ip址址,请重新输入"
fi
##监控远程的一台机器(假设ip为123.23.11.21)的存活状态,当发现宕机时发一封邮件给你
##write by 2016-01-08
read -p "please enter a ip address: " ip
if [ -n "$ip" ]&&[ -z `echo "$ip"|tr -d "."|sed 's/[0-9]//g'` ];then
while :;do
##ping -q $a -c 2
if ping $ip -c1|grep -q "ttl=";then
echo -e `date +%F" "%T`"\t$ip is good!"
sleep 10
continue
else
echo "ping [$ip] failed,please check ! "
echo "ping [$ip] failed,please check ! " |mail -s "$ip bad" abc@139.com
exit
fi
done
else
echo "输入值为空或不是正确的ip址址,请重新输入"
fi
0
#!/bin/bash
while true
do
res=`ping -c5 123.23.11.21 | grep packet |awk '{print int($6)}'`
if [[ $res -eq 100 ]];then
echo "123.23.11.21 is down" |mail -s "down" abc@139.com
fi
sleep 30
done
while true
do
res=`ping -c5 123.23.11.21 | grep packet |awk '{print int($6)}'`
if [[ $res -eq 100 ]];then
echo "123.23.11.21 is down" |mail -s "down" abc@139.com
fi
sleep 30
done
0
#!/bin/bash
#write by 2016-2-2
ping_fun(){
if ping -c $1 $2 > /dev/null 2>&1
then
return 0
else
return 1
fi
}
host=192.168.12.253
count=2
while :
do
ping_fun $count $host
if [ $? -eq 0 ]
then
echo "$host is up"
else
echo "$host is down " |mail -s "$host is down " abc@139.com
fi
sleep 3
done
#!/bin/bash
#write by 2016-2-2
ping_fun(){
if ping -c $1 $2 > /dev/null 2>&1
then
return 0
else
return 1
fi
}
host=192.168.12.253
count=2
while :
do
ping_fun $count $host
if [ $? -eq 0 ]
then
echo "$host is up"
else
echo "$host is down " |mail -s "$host is down " abc@139.com
fi
sleep 3
done
0
#!/bin/bash
ping -c3 -w10 www.baidu.com >/dev/null 2>/dev/null
PING=`echo $? `
while :
do
if [ $PING -eq 0 ]
then
echo "123.23.11.21 一切正常"
else
echo "123.23.11.21Server downtime"|mail -s "downtime" abc@139.com
fi
sleep 30
done
ping -c3 -w10 www.baidu.com >/dev/null 2>/dev/null
PING=`echo $? `
while :
do
if [ $PING -eq 0 ]
then
echo "123.23.11.21 一切正常"
else
echo "123.23.11.21Server downtime"|mail -s "downtime" abc@139.com
fi
sleep 30
done
0
本帖最后由 gxp2008 于 2016-3-1 21:09 编辑
#!/bin/bash
a=`ping -c10 www.baidu.com|grep '% packet loss' |awk '{print $6}' |sed 's/%//'`
if [$a -eq 0]
then
echo "host is down" |mail -s "host is down" abc@139.com
else
echo "the packet not loss"
fi
#!/bin/bash
a=`ping -c10 www.baidu.com|grep '% packet loss' |awk '{print $6}' |sed 's/%//'`
if [$a -eq 0]
then
echo "host is down" |mail -s "host is down" abc@139.com
else
echo "the packet not loss"
fi
0
while :
do
ping -c10 123.23.11.21
if [ $? -ne "0" ]
then
echo "The server is down." |mail -s "down" abc@139.com
fi
sleep 30
done
do
ping -c10 123.23.11.21
if [ $? -ne "0" ]
then
echo "The server is down." |mail -s "down" abc@139.com
fi
sleep 30
done
0
while :; do if `ping -c 1 www.baidu.com |grep -q "error"`; then echo "邮件内容" |mail -s "主题" abc@139.com; fi ; sleep 30; done
0
#!/bin/bash
##监控主机是否存活
packet=`ping -c10 123.23.11.21 |grep 'packet' |awk {print $6} |sed 's/%//g'`
whlie [ $packet -eq 100 ]
do
echo "Your Server is lost" |mail -s "monitor" abc@123.com
sleep 30
done
##监控主机是否存活
packet=`ping -c10 123.23.11.21 |grep 'packet' |awk {print $6} |sed 's/%//g'`
whlie [ $packet -eq 100 ]
do
echo "Your Server is lost" |mail -s "monitor" abc@123.com
sleep 30
done
0
本帖最后由 smatch 于 2016-5-30 21:41 编辑
#!/bin/bash
while
do
ping -c10 123.23.11.21
a = `echo $?`
if [ $a -eq 0 ];then
echo
sleep 30
else
echo "宕机" |mail -s "宕机" abc@123.com
fi
done
#!/bin/bash
while
do
ping -c10 123.23.11.21
a = `echo $?`
if [ $a -eq 0 ];then
echo
sleep 30
else
echo "宕机" |mail -s "宕机" abc@123.com
fi
done
编辑回复