Last active
May 16, 2021 16:05
-
-
Save adharshkamath/7fc20f1b10c43e755e8398ad48409de5 to your computer and use it in GitHub Desktop.
A script to check if a URL is working or not
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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