Homemade Automatic Domain Tester with PhantomJS Part 3
13 Mar 2015Previously on Bitpi
If you have stumbled across this post and haven’t read the previous posts, check them out. Also, the code can be found here.
Previously, we built a domain tester than tested all the sites that we included in our array. Then we hooked it up to cron job to run on a schedule. Now we need to give our program some sort of output show we know how the testing is going.
Tools within My Reach
- Raspberry Pi
- JavaScript
- PhantomJS
- A list of websites to test
Things to do this time around
Create an output ‘log.txt’ text file.
Let’s edit domain_tester.js
Open your domain_tester.js file in a text editor.
We’ll need to declare some new variables at the beginning of the program. ‘fs’ is for the file system module in PhantomJS. ‘log.txt’ is going to be our output file.
At the end of the program we need to state what we want to write to the log.txt file. Some good ideas might be to include:
- The date the program ran
- How long it took to run
- How many sites it tested
- How many sites succeeded
- How many sites failed
So we’ll include the following..
Now we have to use the write method to update the file. The ‘a’ tells it to append (add to) the file instead of overwriting what may already be in the file, which would be ‘w’. Since we want to run this program over and over, we don’t want to overwrite any information.
So before the program exits PhantomJS, lets add this line..
Notice we inluded ‘logcontent’, the array with all the stuff we want listed in our file.
Now when our domain tester runs, it will keep a log of what happens! Even while we are nestled in our beds!