Last active
August 21, 2020 14:22
-
-
Save Carolain/ebe5097c82951d03144bd1f6ba355a0e to your computer and use it in GitHub Desktop.
Keep pinging google.com and beep on success, so I know my flaky connection is working again
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo pinging google.com, will exit on success | |
echo ctrl+c to force exit | |
echo will beep on exit | |
echo | |
ping_cancelled=false # Keep track of whether the loop was cancelled, or succeeded | |
until ping -c1 google.com >/dev/null 2>&1; do sleep 60; done & # The "&" backgrounds it | |
trap "kill $!; ping_cancelled=true" SIGINT | |
wait $! # Wait for the loop to exit, one way or another | |
trap - SIGINT # Remove the trap, now we're done with it | |
if command -v speaker-test &> /dev/null # Ubuntu | |
echo "(the 'speaker-test killed' messages are normal)" | |
fi | |
for i in {1..3} | |
do | |
if command -v speaker-test &> /dev/null # Ubuntu-tested (18.04.4) | |
then | |
( speaker-test -t sine -f 1000 >/dev/null)& pid=$! ; sleep 0.18s ; kill -9 $pid # This beeps | |
sleep 0.1s | |
elif command -v afplay &> /dev/null | |
then | |
afplay /System/Library/Sounds/Glass.aiff # OSX-tested (El Capitan) | |
fi | |
done | |
echo | |
echo "Done pinging, cancelled=$ping_cancelled" | |
# https://serverfault.com/questions/42021/how-to-ping-in-linux-until-host-is-known | |
# https://superuser.com/questions/598783/play-sound-on-mac-terminal | |
# https://stackoverflow.com/questions/592620/how-can-i-check-if-a-program-exists-from-a-bash-script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment