Skip to content

Instantly share code, notes, and snippets.

@maolopez
Last active February 9, 2017 01:38
Show Gist options
  • Save maolopez/e0b5962eb653d13dde83c5ee1a651a68 to your computer and use it in GitHub Desktop.
Save maolopez/e0b5962eb653d13dde83c5ee1a651a68 to your computer and use it in GitHub Desktop.
Monitor any http by issuing a curl and creating a error log in case that http != 200
#!/bin/sh
location=$1
If [ -z "$location" ]
then
echo "please provide the location argument without http://"
exit
fi
res=`curl -s -L -I $location | grep HTTP/1.1 | awk '/200/ {count++} END{print count}'`
if [ "$res" = "0" ]
then
mkdir /home/user/scripts/$location
cd /home/user/scripts/$location
wget -drc --tries=2 http://$location/ -o log
cat /home/user/scripts/$location | grep -i "error" | echo "ACTION REQUIRED: $location is down"
fi
echo "DONE! $res"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment