Stop yelling at your Router

Have you ever been frustrated when your internet goes down, and you're stuck repeatedly refreshing your browser, wondering if it’s back yet? We've all been there. Enter this one-liner Bash script to silently monitor your connection, and the moment you’re back online, it’ll alert you by yelling out "Internet!". Sit back, relax, and let the script do the waiting for you!
$ watch -n 4 "ping -c 3 www.google.com | grep --line-buffered -q 'bytes from' && spd-say 'internet'"
Word-wrapped version for better readability:
watch -n 4 \
"ping -c 3 www.google.com | \
grep --line-buffered -q 'bytes from' && \
spd-say 'internet'"
Breakdown:
watch -n 4
: Run the program continuously every 4 seconds.ping -c 3 www.google.com
: Ping google.com with 3 ECHO_REQUEST packets and stop.grep --line-buffered &&
: Run grep on every newline written to stdout.-q 'bytes from'
: Exit immediately with zero status if any match is found.&&
: Run the next command if the previous command exits with return code 0.spd-say 'internet'
: spd-say, which is available on Ubuntu, sends text-to-speech output request to speech-dispatcher process which handles it and ideally outputs the result to the audio system.
If you have added any cool features to the script, feel free to leave a comment below. 🙂
Happy hacking, and may your Internet stay strong!