好的,所以我需要不断监控多个路由器和计算机,以确保它们保持在线。我在这里找到了一个很棒的脚本,如果无法ping通单个IP,它将通过咆哮通知我(这样我就可以在手机上获得即时通知)。我一直在尝试修改脚本以 ping 多个地址,但运气不佳。当脚本一直在监视在线服务器时,我无法弄清楚如何 ping 关闭服务器。任何帮助将不胜感激。我没有做过太多的 shell 脚本,所以这对我来说很新。
谢谢
#!/bin/sh
#Growl my Router alive!
#2010 by zionthelion73 [at] gmail . com
#use it for free
#redistribute or modify but keep these comments
#not for commercial purposes
iconpath="/path/to/router/icon/file/internet.png"
# path must be absolute or in "./path" form but relative to growlnotify position
# document icon is used, not document content
# Put the IP address of your router here
localip=192.168.1.1
clear
echo 'Router avaiability notification with Growl'
#variable
avaiable=false
com="################"
#comment prefix for logging porpouse
while true;
do
if $avaiable
then
echo "$com 1) $localip avaiable $com"
echo "1"
while ping -c 1 -t 2 $localip
do
sleep 5
done
growlnotify -s -I $iconpath -m "$localip is offline"
avaiable=false
else
echo "$com 2) $localip not avaiable $com"
#try to ping the router untill it come back and notify it
while !(ping -c 1 -t 2 $localip)
do
echo "$com trying.... $com"
sleep 5
done
echo "$com found $localip $com"
growlnotify -s -I $iconpath -m "$localip is online"
avaiable=true
fi
sleep 5
done