#!/bin/bash # make the file executable # run the script as ./check_service.sh # 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