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
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?
You can do this in realtime by using "ip monitor". This will output any events such as the ip address being removed or added the link state changing from operational to disconnected, or a route changing in some way.
You must open in append mode. If you want to leave it to run outside of the terminal you can just disown the job with "disown %1"
If you need timestamps too, theres a couple of ways. An easy way is to use inotifywait to check if the file gets an update, then append your date to it. Itd be easy to do the above and this into a shell script and perhaps disown that instead so you get
Enjoy
Your solution with 'watch' command is not good. I would try to solve this with something like this:
and then run it as normal script: ./script_name.sh
terminate with CTRL+C.
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.
It goes defunct because it is already finished but depends on a parent process -
watch
command which is still alive.That script is already print the date when the remote system is down:
echo "Host : $myHost is down (ping failed) at $(date)" | mail -s "$SUBJECT" $EMAILID
It is
ping
ing with-c 1
so it will stop after sending 1 ECHO_REQUEST packet.Put it in cron to run every minutes: