Yesterday, I started adding a random page link to this site. You can see a couple of the short bash scripts I created there. The project so far is less than 20 lines of real code. It’s resource-light. And it seems to be working in the general sense.
I run the script randpage-index once a day by editing the crontab for the user that runs the web server with
sudo crontab -u www-data -e
and adding the line
@daily /home/twoprops/randpage-index
So far, so good. But the next script, randpage, needs to run frequently. I’ve settled on every 2 seconds for now, as it only uses about 13ms on my system and anyone who is going through random pages on my site at more than 30 pages/minutes is either a bot or needs psychiatric evaluation. The service I used for randpage-index, cron, will only run once per minute at the max. That isn’t nearly fast enough. The most whimisical solution I found for this was from a comment by Dennis Williamson on StackExchange. Read the comment for details. The command is:
nohup watch -n 2 /home/twoprops/randpage >/dev/null &
It works! Unfortunately, it needs to be run with each reboot. Normally one can do that by putting in a crontab line like:
@reboot nohup watch -n 2 /home/twoprops/randpage >/dev/null &
but alas, that isn’t working for some reason. I’ll have to keep at it.
The remaining problem is getting the random links at the bottom of every page. You’ll notice that this page has one, as does the previous page and the index. Also, you can go to a random page manually by surfing to http://twoprops.net/random.
I’ll get the other 600 or so pages updated soon.
—2p