Last active
August 29, 2015 14:02
-
-
Save ET-CS/ff86c2f9a59634ddd70d to your computer and use it in GitHub Desktop.
Bash shell script file to test websites availability and email if status is offline
This file contains hidden or 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 | |
# This script made in centos - you may need to change the command above according to your system | |
# ------------------------------------------ | |
# Website status checker. | |
# save all websites to check in file named 'websites.txt'. each in new line. | |
# end file with empty line. | |
# ------------------------------------------ | |
# Quiet mode. enable to disable echo's command. for crontab, etc. | |
QUIET=false | |
# Send mail in case of failure to: | |
[email protected] | |
LISTFILE=websites.txt | |
function test { | |
if wget $1 -q --spider | |
then | |
if [ "$QUIET" = false ] ; then | |
echo "website up" | |
fi | |
else | |
if [ "$QUIET" = false ] ; then | |
echo "website down" | |
fi | |
# Disable the mailx and enable mail if you don't have mailx installed. | |
# using mail command | |
#mail -s "$p WEBSITE DOWN" "$EMAIL" | |
# using mailx command | |
echo "$p WEBSITE DOWN" | mailx -s "$1 WEBSITE DOWN" $EMAIL | |
exit | |
fi | |
} | |
while read p; do | |
if [ "$QUIET" = false ] ; then | |
echo $p | |
fi | |
test $p | |
done < $LISTFILE |
This file contains hidden or 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
www.example.com | |
www.example.net | |
www.example.org |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment