I once had a script to take a photo of my screen every minute and upload it. I've tried to create something similar for you here. As Mordoc mentioned, you can use scrot . You will have to sudo apt-get install scrot
first.
Here's the script. The lines starting with "#" are comments, so I'll use them to try and explain it:
#!/bin/bash
# ^This first line just tells linux which script language to use.
# We're using bash
# Because this script runs as a Cron-job, it runs as root and doesn't
# necessarily know which user you're logged in as. For me, this says "use
# the default display, ie the first person logged in on the computer"
DISPLAY=:0
HOME=/home/vose
export DISPLAY
export HOME
# Create the screenshots directory in case it doesn't exist yet
mkdir -p /home/vose/Pictures/Screenshots/
# Delete any screenshots more than 7 days old.
find /home/vose/Pictures/Screenshots/ -type f -mtime +7 -delete
# Launch the browser (I use firefox for normal, so I'll use chrome for this)
# The "sudo -u vose ..." means "run the command as user `vose`". You'll
# You'll need to put your username in there...
# The "&" at the end means 'launch in the background', so the script
# can keep going.
echo "Opening the browser"
sudo -u vose chromium-browser http://google.com &
# This records the ProcessID (pid) of the last opened program
# (chromium) so we can kill it later
pid=$!
# Wait 10 seconds for the browser to open and page to load
# On a slow computer/connection/webpage you may need to wait longer
sleep 10
# Take the screenshot using scrot. Save it to this file
scrot /home/vose/Pictures/Screenshots/screenshot_`date +%F-%H-%M-%S`.jpg
echo "Created screenshot_`date +%F-%H-%M-%S`.jpg"
# Kill the browser
kill $pid
Before you try go too far, stop and see if this works.
First, save the script above as takeScreenshot.sh
.
Then from a terminal, type chmod +x takeScreenshot.sh
(Chmod changes the permissions on a file, and '+x' means we're giving it permission to "execute" the script.)
Run ./takeScreenshot.sh
from a command line - this will run the script manually. See if the file shows up in your pictures folder after doing this.
If that worked, we need to now add it to Cron.
At a command line, type sudo crontab -e
. (If it asks you which editor, choose Nano. If you haven't used it before, ask around for some help).
In the file, you want to add a line at the bottom, like this:
# m h dom mon dow command
*/5 * * * * /home/vose/Scripts/takeScreenshot.sh
What this says:
- Every 5 minutes
- Every hour, every day-of-month, every month, every day-of-week
- Run "/home/vose/Scripts/takeScreenshot.sh"
(one small gotcha: make sure there is a blank line after your entry in the crontab. The last line of the file gets ignored, so you need a blank line after your command).
Well, I hope this long post helps! There might be ways to do this without the command line, but you'll have to look around.