Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #Script is intended for sending reports if a desired host is down using ping.
- #Set your hosts in the HOSTS=" " section
- #Set the count value to the desired number of pings
- #BE SURE to change your email
- #be sure to set the file permission so the cron job can run it
- ### Parameters ###
- logfile="/tmp/ping_report.tmp"
- email="[email protected]"
- subject="Ping Status Report from FreeNAS"
- HOSTS="google.com 192.168.1.5 freenasiscrunk.com" #enter your local IPs to monitor here
- COUNT=4
- ### email headers ###
- (
- echo "To: ${email}"
- echo "Subject: ${subject}"
- echo "Content-Type: text/html"
- echo "MIME-Version: 1.0"
- echo -e "\r\n"
- ) > "$logfile"
- for myHost in $HOSTS
- do
- count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
- if [ $count -eq 0 ]; then
- # Failed, creating report
- echo "<pre style=\"font-size:14px\">" >> "$logfile"
- (
- echo "Host : $myHost is down (ping failed) at $(date)"
- ) >> "$logfile"
- sendmail -t < "$logfile"
- rm "$logfile"
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement