Created
April 11, 2013 14:40
-
-
Save mondalaci/5363905 to your computer and use it in GitHub Desktop.
Ping HOSTNAME and if it's down then WOL it and send a notification mail to the admin.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ $# -ne 2 ]; then | |
echo "Usage: $0 HOSTNAME NOTIFICATION-SCRIPT-URL" | |
echo "Ping HOSTNAME and if it's down then WOL it and send a notification mail to the admin." | |
echo "NOTIFICATION-SCRIPT-URL?host=HOSTNAME will be fetched to send the actual mail." | |
echo "Example: $0 mybox http://mydomain.com/notifyme.php" | |
exit | |
fi | |
watched_host=$1 | |
notification_script_url=$2 | |
watched_host_down_file=/tmp/$watched_host.down | |
ping -c 1 -W 1 $watched_host > /dev/null | |
is_watched_host_alive=$? | |
if [ $is_watched_host_alive -eq 0 ]; then | |
if [ -e $watched_host_down_file ]; then | |
echo "$watched_host has been woken up" | |
rm -f $watched_host_down_file | |
wget $notification_script_url?host=$watched_host | |
fi | |
else | |
echo "waking up $watched_host" | |
touch $watched_host_down_file | |
wol $watched_host | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment