For the server, the online rate is very important, there are problems to be resolved in a timely manner, but the system administrator can not be kept in the computer next to the site through the script to monitor the problem in a timely manner through mail notify the administrator, if it is 139 mailbox can also be free mobile phone SMS notification.
Note: Sending mail directly through the system is easy to intercept, and you can use mail to connect to a third party SMTP to send mail.
Shell Script Implementation code:
Copy Code code as follows:
#!/bin/bash
#set-X
While True
Todo
list= (www.jb51.net s.jb51.net)
Mail=jmj@jb51.net
date=$ (date-d "Today" + "%y-%m-%d-%h:%m:%s")
I=0
id=${#list [*]}
While [$i-lt $id]
Todo
If Ping-c1 ${list[$i]} >/dev/null
Then
echo $date: Server ${list[$i]} can ping.
Else
If Curl-m ${list[$i]} >/dev/null
Then
echo $date: Server ${list[$i]} Ping is not available to open the Web page.
Else
echo "Hello, according to system monitoring Server ${list[$i]} can not access and ping impassability, please deal with!" Failure occurred: $date "|mail-s" Server ${list[$i]} cannot connect! Failure occurred: $date "$mail
Until
date=$ (date-d "Today" + "%y-%m-%d-%h:%m:%s")
PING-C1 ${list[$i]} >/dev/null && echo "Congratulations! Server ${list[$i]} has returned to normal, recovery time: $date "|mail-s" Server ${list[$i]} has returned to normal! Recovery time: $date "$mail
Todo
Sleep 5
Done
Fi
Fi
Let i++
Done
Sleep 60
Done