Skip to content

Instantly share code, notes, and snippets.

@icasimpan
Created April 27, 2018 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icasimpan/81d350236a6637729be2a8f8a8a1d232 to your computer and use it in GitHub Desktop.
Save icasimpan/81d350236a6637729be2a8f8a8a1d232 to your computer and use it in GitHub Desktop.
DIY simple uptime checker via shell
### Credentials file '/home/user/.credentials.txt for additional protection be chmod to 600.
### Sample creds content:
### --user youruser:password_here
### This could then be run from cron every 15mins:
### */15 * * * * /home/user/monitor.sh
###
#!/bin/bash
site_urls="https://www.google.com http://ismael.casimpan.com/"
for each_url in $site_urls; do
reply_code=$(curl --config /home/user/.credentials.txt -Is $each_url | grep HTTP | cut -d' ' -f2)
if [[ $reply_code != 200 ]]; then
$(echo "See user cron /home/user/monitor.sh (ticket XXXX)." | mail -s "$each_url DOWN!" me@youremail.com)
fi
done
@icasimpan
Copy link
Author

'--config' would have this value:

-u username:password

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment