Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Use a shell script and Growl to report a router's status UNIX
Growl my Router Alive! is a bash shell script that will ping an IP address (ie a router) and will notify you, using Growl, if the ping is successful. This requires some Terminal basics, both Growl and growlnotify being installed, and a document with a notification icon for Growl. Enjoy.

I wrote this because I have a wireless connection with a D-Link router that is quite annoying because it sometimes drops its wireless network or internet connection. This script will keep pinging my router and sends an alert when the wireless connection is dropped, and when it comes online again.

Here's the code:
#!/bin/sh

#Growl my Router alive!
#2010 by zionthelion73 [at] gmail . com
#use it for free
#redistribute or modify but keep these comments
#not for commercial purposes

iconpath="/path/to/router/icon/file/internet.png"
# path must be absolute or in "./path" form but relative to growlnotify position
# document icon is used, not document content

# Put the IP address of your router here
localip=192.168.1.1

clear
echo 'Router avaiability notification with Growl'

#variable
avaiable=false

com="################"
#comment prefix for logging porpouse

while true;
do
if $avaiable
then
  echo "$com 1) $localip avaiable $com"
  echo "1"
  while ping -c 1 -t 2 $localip
    do
      sleep 5
    done
  growlnotify  -s -I $iconpath -m "$localip is offline"
  avaiable=false
else
  echo "$com 2) $localip not avaiable $com"
  #try to ping the router untill it come back and notify it
  while !(ping -c 1 -t 2 $localip)
  do
   echo "$com trying.... $com"
   sleep 5
  done
  
  echo "$com found $localip $com"
  growlnotify -s -I $iconpath -m "$localip is online"
  avaiable=true
fi

sleep 5

done
Copy this script into a directory as a script named pingrouter.sh or whatever; the name of your shell script must end with a .sh. Make the script executable by typing chmod ugo+x pingrouter.sh. Execute the script with sh ping.sh. Comments and suggestions are always welcomed!

[robg adds: I haven't tested this one.]
    •    
  • Currently 2.57 / 5
  You rated: 1 / 5 (14 votes cast)
 
[9,437 views]  

Use a shell script and Growl to report a router's status | 6 comments | Create New Account
Click here to return to the 'Use a shell script and Growl to report a router's status' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
.sh not necessary
Authored by: googoo on Apr 08, '10 09:43:29AM

There is no requirement for a shell script to have a .sh ending. The chmod command makes the file executable regardless of the extension. In fact, the command line does not distinguish between extensions except that they are part of the filename. The .sh extension is a convenience to the user although it may allow the finder to associate the file with a particular application when opened.

-Mark



[ Reply to This | # ]
Prowl notifications for downtime
Authored by: lullabud on Apr 08, '10 10:03:29AM

Combine this with prowl and have it check for failed pings and you would get notifications on your iPhone only when your router goes down.



[ Reply to This | # ]
Use a shell script and Growl to report a router's status
Authored by: ljharb on Apr 08, '10 01:38:50PM

Perhaps a better tip would be to buy network hardware that doesn't intermittently fail it's primary function. D-Link tends to have had this problem consistently throughout the last decade.



[ Reply to This | # ]
Use a shell script and Growl to report a router's status
Authored by: zionthelion73 on Apr 13, '10 04:35:54AM

Thanks for commenting, which router would you suggest? I would love to have Wireless Dsl Router with LAN band shaping.



[ Reply to This | # ]
Use a shell script and Growl to report a router's status
Authored by: fooljay on Apr 12, '10 10:56:45AM
Am I to assume that you have never tried the excellent Hardware Growler? If a loss of wireless was indicative of your router going down, Hardware Growler will tell you that plus a heck of a lot more.

[ Reply to This | # ]
Use a shell script and Growl to report a router's status
Authored by: zionthelion73 on Apr 15, '10 01:09:26AM

Yes I just tried the excellent Hardware Growler but it notifies when an interface comes up or down not if a IP is avaiable.



[ Reply to This | # ]