I am Currently trying to make a shell script that will email me and other receipients if the website says it is down for maintenance. Curently i am trying to use curl and grep to pipe to a variable if grep see’s the Phrase “Down for Maintenance” but when even when the website does not say that it it still outputs information. I want to make it so if the phrase exists it will make a vairiable true else it is false and just exits. Btw this is for a cronjob.
Here is what i have come up with so far. P.S sorry for being such a noob.
## Sends an email if the website is down for maintanance
#RESPONSE = ''
curl websiteaddress.com | grep "Down for Maintenance" | read RESPONSE
if $RESPONSE
then
echo "Website is Down" | mail -s "Website is down for maintenance" email@address.com
end else
exit
Change:
To:
The
grep -qtells grep to operate in “quiet mode”, meaning it won’t output anything. Instead it will exit with a return code of zero if a match was found, 1 if no match was found. theif [ $? -eq 0 ]checks the return code of grep.