Mostly is very usefull to know if one or another website is down. Here is simple example to monitor your websites:
This file contains 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/sh | |
# script to check website status (online/ofline) | |
while read site | |
do | |
if ping -w 60 -c1 -q "$site" &>/dev/null; then | |
echo "$site is up" # for debug | |
else | |
# action to do if website offline | |
echo "[$(date +%d-%m-%Y:%H:%M:%S)] $site is not reachable." | slackpost.sh | |
fi | |
done < /path/to/file/sites.txt # list of sites to check |
sites.txt example
website1.com website2.com
Now you can add it to crontab. Type crontab -e and insert:
# ping websites every minute * * * * * /path/to/monitor-websites.sh > /dev/null
The script use my notification function to slack. This tutorial you can find at [Tutorial] send message with linux to slack
Example of message in slack if website is offline:
Very nice tutorial. Thak you
Im not very advanced programmer, but i found this tutorial very useful and easy to understand.