Dealing with Time Wasters

Reading draws me in.  While this has done me much good in my life, it also means that I can easily get sucked into reading a news site, and waste too much time.  It took me a long time to figure out how to effectively block sites that I want to browse occasionally.

To start with, I realized that I could block a site by putting an entry into /etc/hosts.  For example, If I want to block facebook.com, I have:

127.0.0.1 www.facebook.com facebook.com

This prevents the browser from opening the page, due to it not being found in DNS.

However, I do periodically want to catch up with friends and family, so I would edit that file, and comment out the line:

#127.0.0.1 www.facebook.com facebook.com

However, from there on, I could browse it again, and I was wasting time.

A simple script removes the comment characters:

$ cat ~/bin/disable_hosts

contains

#!/bin/sh
TEMP=`mktemp`
cat /etc/hosts | sed 's!^#127!127!' > $TEMP 
sudo mv $TEMP /etc/hosts
sudo chmod a+r /etc/hosts

But I had to remember to run that. And via sudo.  I wanted it automated.  The solution was cron.

$ sudo crontab -l
0 * * * * /home/ayoung/bin/disable_hosts

Runs it hourly, at the top of the hour. After that, my timewasters are blocked again.

 

Leave a Reply

Your email address will not be published. Required fields are marked *