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?
3 Answers
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:
#!/bin/bash
while "true"
do
ping -w 10 -c 5 www.google.com
if test $? -ne '0'
then
spd-say "connection lost"
sleep 3s
fi
done
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. :)
- 2,439
- 2
- 25
- 32
While
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 8.8.8.8 || 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).
- 1,098
ping -A 1.2.3.4 The uppercase A parameter to send us a beep sound whenever the target stops replying to our ping.
- 1