Linux automation - Capturing screenshots
Using crontab and a simple shell script we can configure Linux to take screenshots at defined intervals.
Create a file called screen.sh and place it in /home/<username>/bin and give it execute permissions
#!/bin/bash
cd /home/laszlo/screenshots
DISPLAY=:0.0 import -window root screen` date|awk 'OFS="."{print $2,$3,$6,$4}'`.png
Modify the cd command to suit your environment
date|awk… appends the date and time to the filename (so we don’t overwrite the previous ones)
Now we just need to use crontab to execute the script at regular intervals
~>crontab -e
this brings up the editor, insert a similar line and save the file (Press Esc and then SHIFT ZZ to save and exit VI)
0,30 * * * * /home/laszlo/bin/screen.sh
Cron will execute the script /home/laszlo/bin/screen.sh on minute 0 and 30 each hour every day
Notice the comma between the 0 and the 30. That is to separate the values of the first field.
for more detail on crontab and its paramaters see crontab
One thing I wanted to get working is to ignore when the computer was idle. This program should give you the idle time of the machine, you can use the output to determine whether to take a screenshot - getting idle time in Linux
#!/bin/bash
cd /home/laszlo/screenshots
idle=$(/home/laszlo/bin/idle)
if [ $idle -lt 60000 ]; then
DISPLAY=:0.0 import -window root screen` date|awk 'OFS="."{print $2,$3,$6,$4}'`.png
else echo "User idle for :" $idle
fi
You can also edit the crontab entry to not capture at night when you are sleeping.
Tags: automation, Linux, screenshot, scripting, shell
March 18th, 2009 at 7:33 am
Hello,
Not sure that this is true:), but thanks for a post.
Thank you
Nadine
July 31st, 2009 at 10:38 pm
I might change for the look kind of sexy for a Linux distro.
August 1st, 2009 at 3:59 pm
hahaha ! this is good shit
gorethrasher.com - cool!!!!
August 7th, 2009 at 11:59 pm
Thanks for post. Nice to see such good ideas.
August 9th, 2009 at 3:29 am
The article is ver good. Write please more