Skip to content

Instantly share code, notes, and snippets.

@erickvasilev
Last active May 17, 2017 09:50
Show Gist options
  • Save erickvasilev/34c35f07e7b238a356047cb30ba9c762 to your computer and use it in GitHub Desktop.
Save erickvasilev/34c35f07e7b238a356047cb30ba9c762 to your computer and use it in GitHub Desktop.
Bash Script - Check If Server is Down/Up
#!/bin/bash
# scanning website and save to status.txt
wget -q -O /var/www/test/status.txt bahrulilmi.com --timeout 10 -t 1
cd /var/www/test/
File=status.txt
# check if there is <title> metadata , if site is not accessible / timeout, file will be empty
if grep -q title "$File";
then
echo "server is up"
else
echo "Oops!! server is down"
# restart the server (VULTR API), change with your own
curl -H 'API-Key: xxxxxxxxxxxxx' https://api.vultr.com/v1/server/reboot --data 'SUBID=xxxxxxx'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment