Can we set up a voice for disconnetion?

Steve Flynn anothermindbomb at gmail.com
Wed Oct 19 21:56:22 UTC 2011


On 19 October 2011 22:32, PM <ubuntu.bkn at gmail.com> wrote:

>
> Sure - I'll boot up the laptop and crank it out now.
>>
>
Paste the following into a file and make it executable with chmod +x


#!/bin/bash
ping -q -c 3 www.google.com > /dev/null
rc=$?
if [ ${rc} -ne  0 ]
then
espeak "Internet connection may be down" >/dev/null 2>&1
fi

Call this shell script in your crontab as frequently as you'd like to check
the connection.

It'll try to fire 3 packets to www.google.com and will fail with a non-zero
return code if it doesn't get a reply. Adjust this ping command to suit your
needs.

Regardless of what happens with ping, we look at the return code and if it's
not equal to zero we call espeak with a suitable message. This is where
you'd pop your call to an mp3, an alarm noise, fire an email, log into the
router and request it to reset itself, etc.

This is, as you can see, a simplistic script - you could easily extend it to
have multiple attempts before deciding the link was down, or hit multiple
sites multiple times before alerting anyone and so forth. No error handling
in this thing right now - it's not something I'd deploy to a server at work
for example but it shows you the general idea.



-- 
Steve

When one person suffers from a delusion it is insanity. When many people
suffer from a delusion it is called religion.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20111019/23befcdb/attachment.html>


More information about the ubuntu-users mailing list