Skip to content

Instantly share code, notes, and snippets.

@tomoyk
Created August 19, 2022 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomoyk/65c7910b855be30856535f1daf6e99c1 to your computer and use it in GitHub Desktop.
Save tomoyk/65c7910b855be30856535f1daf6e99c1 to your computer and use it in GitHub Desktop.
HTTP Monitoring Script
#!/bin/bash -eu
target_url="http://192.168.5.x/"
timeout_sec=3
logfile="logs/check.log"
mkdir logs || true
touch $logfile
while :
do
current=$(date "+%Y-%m-%d %H:%M:%S")
response=$(curl -o /dev/null -m $timeout_sec -w '%{http_code}' -s $target_url)
if [ $response -eq "200" ]
then
echo -e "$current\t$response\tSuccess" | tee -a $logfile
elif [ $response -eq "000" ]
then
echo -e "$current\t$response\tFail:timeout" | tee -a $logfile
else
echo -e "$current\t$response\tFail" | tee -a $logfile
fi
sleep 60
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment