20Aug Check up-time using your own servers
There are plenty of free services out there that will check if your websites are up (list) and these are great for someone for just wants occasional checks. Most of these services are quite limiting and require you to sign up and create an account when all you want is a simple test.
Recently my internet service has been down multiple times a week and I wanted to setup monitoring. I checked out Pingdom and Mon.itor.us, but there free services didn't check frequently enough. I did some searching and came across a script I could run off my web server (with decent uptime). The script didn't quite meet my needs so I adapted it into the following:
#!/bin/bash HOSTS='example1.com example2.com' savePath=/home/username for thisHost in $HOSTS do pingResults=`ping -c 4 $thisHost | grep 'received'` received=`echo $pingResults | awk -F',' '{print $2}'` packetLoss=`echo $pingResults | awk -F',' '{print $3}'` time=`date | awk '{print $4}'` day=`date | awk '{print $3}'` month=`date | awk '{print $2}'` year=`date | awk '{print $6}'` date="$year, $month, $day, $time" echo $date, $packetLoss >> $savePath/ping_$thisHost.csv done |
You'll need to add the websites you want to check and change the location of the log file. The script generates a log named "ping_example.com.csv" that contains the time and date of ping and the packet loss.
To automate to the process you can add a cronjob that executes the script every few minutes. Upload the ping script to your server. After it's uploaded, SSH into your server and type the following:
crontab -e |
This will open your crontab file containing all your cronjobs. Add the this line to the bottom:
*/3 * * * * sh -c $'/path/to/ping/script/ping.sh' |
"*/3" runs the script every 3 minutes. You can change 3 to any value 0-59.
To save and exit the editor:
For emacs
Ctrl-x then Ctrl-c then hit 'y'
For nano
![]()
Ctrl-x then 'y' then [enter]
After editing and saving the file cron should automatically run the uptime checker script every 3 minutes and save the results to "ping_example.com.csv". You can open this in Excel or another spreadsheet program and generate graphics or reorder/organize it to make it easier to read.
Here are some free alternatives:
Pingdom
Mon.itor.us
Are my sites up?


