Skip to content

Instantly share code, notes, and snippets.

@ET-CS
Last active August 29, 2015 14:02
Show Gist options
  • Save ET-CS/ff86c2f9a59634ddd70d to your computer and use it in GitHub Desktop.
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
#!/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=youremail@another.world
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
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