Skip to content

Instantly share code, notes, and snippets.

@adharshkamath
Last active May 16, 2021 16:05
Show Gist options
  • Save adharshkamath/7fc20f1b10c43e755e8398ad48409de5 to your computer and use it in GitHub Desktop.
Save adharshkamath/7fc20f1b10c43e755e8398ad48409de5 to your computer and use it in GitHub Desktop.
A script to check if a URL is working or not
#!/bin/bash
# make the file executable
# run the script as ./check_service.sh <URL> <any text here>
# make sure curl is installed
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" $1)
CODE_TYPE=${HTTP_CODE:0:1}
if [[ $CODE_TYPE == "4" || $CODE_TYPE == "5" || $CODE_TYPE == "0" ]]
then
echo "$(date) --- $1 service is not working or does not exist!"
else
echo "$(date) --- $1 service working!"
fi
if [[ $2 != "" ]]
then
crontab -l | { cat; echo "* * * * * $0 $1 >> ./logs.txt 2>&1"; } | crontab -
# edit the crontab args to fit the necessary time interval
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment