Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

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.

share|improve this answer
    
This is nice post-up and post-down options. that is what i was looking for. –  YumYumYum Nov 13 '12 at 9:42
add comment

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.

share|improve this answer
    
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 –  YumYumYum Nov 13 '12 at 9:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.