design a script that monitors the surviving state of a remote machine (assuming IP 123.23.11.21) and sends a message to yourself when it finds an outage.
Tips:
1. You can use the ping command ping-c10 www.baidu.com
2. The order to send the email is echo "Email content" |mail-s "subject" [email protected]
3. The script can be turned into a dead loop, detected once every 30s
#!/bin/bash#remote monitoring. If the network is broken,email me~ #2015/07/23 ping-c10 www.baidu.com > 33.logt=$ (awk ' {print $} ' 33.log) while ["1" = "1"]do if [!-Z $ ($t)];then echo "" Else echo "Diaoxianle" |mail-s "Down" [email protected] fi Sleep 30done
There is an error in the previous formulation, that is, the email is 30s once ... Not appropriate, and then write a modified version of the
#!/bin/bash#remote monitoring. If the network is broken,email me~ #2015/07/23ping-c10 www.baidu.com > 33.logt=$ (awk ' {print $} ' 33.log) while ["1" = "1"]do if [!-Z $ ($t)];then echo "" Sleep "else break; Fidone echo "Diaoxianle" |mail-s "Down" [email protected]
That would just send me an email.
Shell exercises-Remote monitoring