4

How can i make beep sound in the PC when the network cable is unplugged or no network available to any specific interface such as eth0 or eth1?

Follow up:

$ sudo apt-get install beep
$ cat /etc/modprobe.d/blacklist.conf | grep 'pcspkr'
blacklist pcspkr
$ sudo vim /etc/modprobe.d/blacklist.conf
#blacklist pcspkr
:wq
$ sudo modprobe pcspkr
$ beep
4

You're not going to want to keep wgetting infinitly to know if you have network: what you are looking for is a "post-up" script. This is kinda advanced, but you should be able to do this.

First, figure out how to make a sound. You can use the methods @iUngi uses, like echo -e or beep.

To actually add this beeping to the point where you have network, use the information at https://wiki.ubuntu.com/OnNetworkConnectionRunScript

The part you are interested in (but read the whole thing!) is this:

Edit the text configuration file /etc/network/interfaces and add one of the following directive pre-up , post-up , pre-down , post-down to the appropriate network connection, for example :

auto eth0
iface eth0 inet dhcp
name WiFi
post-up /etc/network/if-up.d/myscript.sh

restart your network:

/etc/init.d/networking restart

You can obviously add an extra check ping for instance or just get the headers (curl --head) if your connection isn't always on internet but can be a local connection (and you don't want a beep then), but I think that shouldn't be needed in all cases.

  • This is nice post-up and post-down options. that is what i was looking for. – user25165 Nov 13 '12 at 9:42
1

You can use the following script:

wget --spider http://www.google.com
if [ "$?" != 0 ]; then  
   echo -e '\a'
fi

This check whether the google is reachable or not. If not then beep ones. You can use a while cycle to beep more times. Also you can use cronjob tu check the connectivity.

Also there is beep but also check whether is in the blacklist

cat /etc/modprobe.d/blacklist.conf | grep 'pcspkr'

If it's in the blacklist.conf file you have to uncomment that.

  • Well, echo -e '\a', does not make any beep, but above follow up does make beep sound. Another issue is that i dont have internet and i have to have only alert based on ethernet interface eth0 or eth1 or wlan0 – user25165 Nov 13 '12 at 9:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy