[email protected]:~# ls while50.sh while50.sh[email protected]:~# cat While50.sh #!/bin/bashlogfile=/root/192.168.1.50.ping.logwhile truedo echo -n $ (date +%y-%h:%m:%s) >> $logfile ping -c1 -w1 192.168.1.50 >/dev/null #ping 192.168.1.50 if [ $? -eq 0 ];then echo -n ------ OK >> $logfile else echo -n ------ bad >> $logfile fi echo " " >> $logfile sleep 1done[ email protected]:~# tail -f 192.168.1.50.ping.log 2017-14:03:25 ------ OK 2017-14:03:26 ------ OK 2017-14:03:27 ------ OK 2017-14:03:28 ------ OK 2017-14:03:29 ------ OK 2017-14:03:30 ------ ok 2017-14:03:31 ------ OK 2017-14:03:32 ------ OK 2017-14:03:33 ------ ok 2017-14:03:34 ------ OK 2017-14:03:35 ------ ok
1, the above is the test ping problem, in the monitoring of the alarm when the warning ping to the 192.168.1.50 machine will lose packets, check lost packets, Manual check.
2, the above backstage has been executing, disconnect the terminal or hold unless kill. This allows uninterrupted monitoring.
This article is from the "Summer" blog, please be sure to keep this source http://caimengzhi.blog.51cto.com/9787265/1895026
Shell implements a second-level task in the background