Created
April 13, 2023 06:11
-
-
Save leafsummer/3ce333561c744016e07811fce05a5943 to your computer and use it in GitHub Desktop.
test network latency and packet loss
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 | |
log_file=/var/log/curl_error.log | |
max_age=86400 # one day in seconds | |
max_loop=1000 # maximum number of loops to execute | |
loop_count=0 # current number of loops executed | |
if [ ! -f "$log_file" ]; then | |
touch "$log_file" | |
fi | |
while [ $loop_count -lt $max_loop ]; do | |
if ! curl -sSf https://downloads.wordpress.org/ | grep -q 'nginx'; then | |
current_time=$(date '+%Y-%m-%d %H:%M:%S') | |
echo "Error: $current_time" >> "$log_file" | |
fi | |
sleep 2 | |
loop_count=$((loop_count+1)) | |
if [ $(($(date +%s) - $(date -r "$log_file" +%s))) -ge $max_age ]; then | |
mv "$log_file" "$log_file.old" | |
touch "$log_file" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment