Is there a way to make the Ubuntu 14.04 terminal trigger a success or, if it fails to ping Google, a different sound, such as if the wifi goes down? If so, how would I do so on constant loop in the background, after a certain length of time passes? I assume it would be something like (command); sleep (time length); done or similar?

  • I am not quite sure what you're saying here. You want Ubuntu to make sound when wifi disappears, am I right ? Can you clarify ? – Sergiy Kolodyazhnyy Jan 9 '16 at 1:24
  • 3
    Possible duplicate of Make a sound once process is complete – muru Jan 9 '16 at 2:15
  • Or askubuntu.com/q/409611/158442 – muru Jan 9 '16 at 2:15
  • Something like that. I have (spotty) satellite internet in my area, and since I'm often in a different room than the modem, I was wanting some terminal command that would ping Google and tell me if the connection was successful (like if all packets went through) or if I don't get a reply back (such as when I lose internet connection to the rest of the world). Does that help at all? – Markeus Aythan Alvarez Halberd Jan 9 '16 at 12:15

The question is actually a bit broad, AskUbuntu is for specific questions and this is more like can someone make me a script.
But hey, it's just a couple of lines, let's get you started:

while "true"
    ping -w 10 -c 5 www.google.com
    if test $? -ne '0'
            spd-say "connection lost"
            sleep 3s

Basically we repeat a endless loop with ping and check if it exits with an error. ($? gives the exit-code of the previously executed program).

For timing you can just alter the ping command. Now turn on your speakers and enjoy. :)

  • I think you might want to add some pause time after saying "connection lost," otherwise it just sounds like conne con con con con c c c c c c c c conne con con conne – SuperSluether Jan 9 '16 at 22:59
  • Not exactly, -w is a deadline so no matter how many packet are send times out after this time, -c is the amount of requests it tries to send within this time. If no replies come back they time out so speed will be low. The default interval is 1 second. So I would expect 10 sec on failed connection and 5 sec on a successful connection. However here ping reacts a bit different then I would expect. It only sends out only 3 pings in a timeframe of 2 seconds.. Strange... – Requist Jan 9 '16 at 23:24
  • Well, I just tried running your script. Once the pings time out, it just says connection lost over and over again, but it doesn't finish saying it before it loops again, so it just sounds like it's saying "con" over and over. – SuperSluether Jan 9 '16 at 23:42
  • what time does it display and how many pings are being sent per cycle? – Requist Jan 9 '16 at 23:47
  • Ah, found the problem. I tried with a connection failing but a dns still responding; therefor the packets just time out like expected. When the dns fails also the host becomes unknown and there is no timeout; hence what you see. I'll update to fix that. – Requist Jan 9 '16 at 23:51


ping -a IP_ADDRESS

makes an audible beep (like echo -e "\a") every time it success, I have not found any option in the standard ping command to beep when failure.

Based on @Requist answer, one line that using crontab sets up the desired behavior every 5 minutes may be:

(crontab -l 2>/dev/null; echo "*/5 * * * * /bin/ping -w 10 -c 4 || spd-say 'off'") | crontab -

Note: As this sets up a crontab job, you will need to use crontab -e to disable it by removing the introduced line (or to edit its parameters).


ping -A The uppercase A parameter to send us a beep sound whenever the target stops replying to our ping.

  • This is not a standard option. Please say where this works, and ideally provide some supporting documentation. … … … … … … … … … … … … … … … … Please do not respond in comments; edit your answer to make it clearer and more complete. – G-Man Says 'Reinstate Monica' Jul 3 '19 at 19:32
  • FreeBSD ping command includes such parameter since version 4.5. However, this is AskUbuntu site and I have not found any version of Ubuntu with that behavior. '-A' in Ubuntu is adaptive ping which tries to send packages every time a new package arrives. – arauzo Jul 1 '20 at 12:53

Your Answer

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

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