Skip to content

Instantly share code, notes, and snippets.

@mindware
Created May 26, 2015 16:44
Show Gist options
  • Save mindware/781090e2f1d19356bec1 to your computer and use it in GitHub Desktop.
Save mindware/781090e2f1d19356bec1 to your computer and use it in GitHub Desktop.
Cronjob to check if we're online
#!/bin/zsh
# Saved in ~/online-check.sh and in a cron job as:
# * * * * * ~/online-check.sh
local offline=`dig 8.8.8.8 +time=1 +short google.com A | grep -c "no servers could be reached"`
if [[ "$offline" == "0" ]]; then
rm ~/.offline
else
touch ~/.offline
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment