Homemade Automatic Domain Tester with PhantomJS Part 2
28 Feb 2015Previously on Bitpi
If you have stumbled across this post and haven’t read part one, check it out. Also, the code can be found here.
Reason Why
I had an idea to write a program that automatically checked a list of websites to make sure they were still running. The idea is that I could later modify this program to contact me if a site was down.
Tools within My Reach
- Raspberry Pi
- JavaScript
- PhantomJS
- A list of websites to test
Things to do this time around
In this update, we are going to set up a few things.
- Add a time output that tells us how long the program took to run.
- Hook the program up to a cron job.
Adding a Timer
Grab the current time at the beginning of the program.
Grab the time again at the end of the program
Subtract the start time from the end time to get the total run time.
Convert from milliseconds to seconds. (if you’d like)
Display the output in the console.
Here is what you should see after the program runs..
Automatically running program on a schedule using crontab
Crontab is an essential tool that is included with most linux distros. It can be used to run programs or commands on a schedule. Whether that is every 5 seconds or once a year, that’s up to you!
Get back to the command line and type..
This will open up your command line scheduler.
It’s likely that every line will be commented out if you have yet to use crontab before on your system. We are going to add a line that does not have a hashtag at the beginning.
This will run our domain tester on the hour, every hour.
Possible next steps
The next step for me on this little project will most likely be some sort of log file. There isn’t a whole lot of point to me running this on cron in the background if I’m blind to the status of the tests. So look out for a part 3 as my adventure continues.