I have a bash script that emails me whenever a web server is not responding, and the script is ran by
cron every 5 minutes. However, if the website goes down for a few hours, I'd receive too many messages instead of just one.
What's the best way to make it email only once? Should I use an environment variable and check it before sending the email/resetting it when web server goes up again? Are there better ways to do this (without polluting the environment)? Am I doing something silly right now? I'm not confident in my shell scripting skills.
#!/bin/sh output=$(wget http://lon2315:8081 2>&1) pattern="connected" if [[ ! "$output" =~ "$pattern" ]] then echo "$output" | mail -s "Website is down" "firstname.lastname@example.org" fi