I had to log my hourly effort in my last gig (stupid policy IMO; what am I, a factory worker?) but since I’m not working on Windows, I couldn’t use ManicTime to do the tracking for me.

Taking a cue from oDesk, I decided to make a simple script that takes screenshots of my desktop every few minutes so that I could just review them at the end of the day. For this I used scrot for taking the screenshots and cron for the scheduling.

First install scrot:

$ sudo apt-get install scrot

Then write a script, say /path/to/home/scrot.sh:

#!/bin/sh
LOCATION="$(date +/path/to/home/Pictures/shots/%Y/%m/%d)"
mkdir -p $LOCATION
cd $LOCATION
DISPLAY=:0 scrot '%Y-%m-%d-%H%M.jpg' -q 20

This script will take a low quality screenshot of the desktop and put it in the Pictures/shots folder separated by date.

Set the permissions with chmod:

$ chmod u+x /path/to/home/scrot.sh

You can now test this by running:

$ /path/to/home/scrot.sh

Now time to add the script as a cron job. There are a lot of cron tutorials out there, but to summarize what you need to do, here are the basic steps:

Run crontab -e to edit the cron table file for your current user.

Add a line that will execute scrot.sh whenever you want it to run. For example, here’s the entry for running the script every three minutes on Monday to Friday:

*/3 * * * 1-5 /path/to/home/scrot.sh

Tagged with →  
Share →

3 Responses to Take periodic screenshots in Ubuntu with scrot and cron

  1. asim says:

    Hi,

    I’ve been doing same as you’ve told, but it’s giving me an error when I check the syslog. It says that the Output is Discard. And I’ve tried every possible thing to make it work, but its keep on saying that. Whereas if I type the command / execute the script manually, it works. it doesn’t work with cron jobs.

  2. Scott Fertig says:

    you have to be sure that if you are running it with cron that it runs as your user, and you also have to make sure you are getting the right display (DISPLAY). Better a late reply than never…

  3. Anonymous says:

    Hi,

    Nice Post. I have a query though.

    Is there a way to Email the saved screenshot to an Email ID? Will it be possible to schedule the cron in such a way that it saves the screenshot and Email’s it to a specific Email ID?

    Thanks in advance.

Leave a Reply to Scott Fertig Cancel reply

Google+