Linux – Using watch to run a shell script – but the script goes defunct

bashlinuxpingwatch

So I want to keep an eye on my network connectivity so I can make a report for my ISP. (seems like the modem goes out for about 30-60 seconds about once a day)

So I copied this handy little script

http://www.cyberciti.biz/tips/simple-linux-and-unix-system-monitoring-with-ping-command-and-scripts.html

And an running it with

watch -n 15 ./ping-test.sh

I have been testing it by pulling the plug on my modem.

The first time watch runs the script after the network goes out it runs fine (sends some email) and then goes defunct. Once networking is restored the script "finishes" and then watch runs it again.

So I'm getting mail for when the network goes down, but not how long it was down for.

If I run the script straight from the command line it runs (emails) and then exits.

Any ideas why? How can I get the script to keep running once the network is down?

Best Answer

ping will hang if it cannot reach its target and that maybe why the script goes defunct because the ping is still waiting for a reply. Try adding the -w deadline or -W timeout option to the ping.