midrange.com code scratchpad |
Name:
ping monitoring script
|
Scriptlanguage:
Plain Text
|
Tabwidth:
4
|
Date:
05/02/2012 04:53:36 pm
|
IP:
Logged
|
|
Description:
The user was to lazy to give a description
|
Code:
- #!/bin/sh
-
- HOSTS="host1.example.com host2.example.com"
- EMAIL="joe@example.org"
-
- COUNT=4
-
- for host in $HOSTS
- do
- echo "$(date) : Testing $host" >> monitor.log
- pingresult=$(ping -c $COUNT $host)
-
- count=$(echo $pingresult | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
- if [ $count -eq 0 ]; then
- # 100% failed
- echo "$(date) : $host is down" >> monitor.log
- echo $pingresult | mail -s "Host : $host is down (ping failed) at $(date)" $EMAIL
-
- fi
- done
|
|
|