Bash script: do something when server is responding too slow
Some time ago I had to write script that should perform some actions when server is responding too slow. I had little time for this task, so I wrote simple bash script using cURL, and set is as Cron job.
curl -s URL --max-time 5 > /dev/null 2> /dev/null if [ $? -eq 28 ] then #perform some # actions fi
In above script –max-execution option is used. With this option if connection lasts longer than n seconds (in my example 5 seconds) curl stops and return code 28.