Monitoring services, which are placed on crontab tasks, individuals do not like to use a dead loop to run in the background.
So every time 3 cycles are executed, 3 cycles in a row, and any one of the services is down, the alarm will be reported.
Popularize small knowledge, pay attention to redirect 3 kinds of writing, in fact, the effect is the same.
#!/bin/bashnmap -p 6065 10.31.6.6 | egrep "6065/tcp open" &>/dev/nullcode1=$?nmap -p 80 10.31.6.6 | grep "80/tcp open http " >/dev/null 2>&1code2=$?curl http://10.31.6.6/test.html/ >&/dev/nullcode3=$?my_mail () {mail_list= ("[email protected]" "[email protected]" ) Now_date= ' date "+%y-%m-%d %t" ' for i in ${mail_list[@]}doecho -e "webchat is down,please check;\nip:42.62.5.100\n$now_date " | mail -s " webchat Down " $idone}n=1count=1while ((n<4)) doif [ $code 1 = 0 ] & & [ $code 2 = 0 ] && [ $code 3 = 0 ]then n=$ (($n + 1)) sleep 2else count=$ (($count + 1)) n=$ (($n + 1)) sleep 2 if [ $count -Eq 3 ];then my_mail fi fidone
This article is from the "[email protected]" blog, please be sure to keep this source http://ribble.blog.51cto.com/3863110/1649583
How to monitor whether a running service is healthy and mail alerts