Created
August 19, 2022 10:39
-
-
Save tomoyk/65c7910b855be30856535f1daf6e99c1 to your computer and use it in GitHub Desktop.
HTTP Monitoring Script
This file contains 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 -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