Tiny Core Extensions > TCE Q&A Forum
Taking screen-shots under cron
(1/1)
andydj:
I need to take regular screen-shots (every minute) of the display on a tinycore vm. It needs to be able to take screen-shots, of, say Firefox or a 3270 terminal emulator.
Originally, I used to use Xvfb + import for this, but due to changes in one of the web-pages I'm snapshotting, I need to be able to interact with it to log in (it uses a "special" login screen that I can't automate).
So my latest attempt is to use TinyCore + the firefox and screenshot.sh extensions. Screenshot.sh uses imlib2_grab, I've managed to get working from the command-line perfectly. Now I have got cron running, and added a crontab entry like this:
----------------------------------------------
* * * * * env DISPLAY=:0 /usr/local/bin/imlib2_grab /tmp/screenshot.png >> /tmp/grab.log 2>&1
----------------------------------------------
When I tail /var/log/messages I see the cron job successfully running, and /tmp/grab.log shows the following error message:
----------------------------------------------
No protocol specified
Can't open display :0
----------------------------------------------
If I can get this running, I can then install nginx and will then be able to make the screenshots available on the "smart" TV we use for monitoring the above mentioned web page (the TV can't cope with displaying the page directly).
It's either this or mess round with using a raspberry pi hooked directly to the TV....
TIA
Rich:
Hi andydj
Maybe you could run this modified version of windowshot.tcz:
--- Code: ---#!/bin/sh
#
# Based heavily on Tinycores screenshot.sh, this script captures a
# single window rather than the entire screen. When run, the cursor
# changes to a crosshair. Click on a window to save a .png of it in
# your home directory. Richard Rost 3-19-2013
#
# Modified to take a snapshot once every 60 seconds.
[ -z ${DISPLAY} ] && echo "Requires X" && exit 1
which xwininfo > /dev/null
[ "$?" -ne 0 ] && exec popup "Requires xwininfo, see Xorg-7.(5 or 6)-bin.tcz" && exit 1
WINDOW_ID=`xwininfo -frame | grep " Window id:" | cut -d " " -f 4`
while true
do
/bin/sh -c "imlib2_grab -id $WINDOW_ID /tmp/screenshot.png"
sleep 60
done
--- End code ---
Start it and when the cursor changes to a crosshair, click on the window you want to take snapshots of, or click on the
desktop if you want full screenshots.
You will also need Xorg-7.7-bin.tcz if it's not already installed.
andydj:
Hi Rich, thanks for the suggestion. I'll give it a try, but I was hoping for a less interactive solution - it's bad enough that we have to periodically re-log in to the web service.
This idea avoids running from cron, so it will run under the tc user's context, but because it uses sleep, it will be less regular, though this probably won't matter much. I'll try modifying it to capture the root window instead, so then the only requirement would be that it is running, which would be better.
curaga:
Besides DISPLAY, root needs XAUTHORITY to be able to access tc's screen.
Rich:
Hi andydj
--- Code: ---I'll try modifying it to capture the root window ...
--- End code ---
In that case it could be reduced to this:
--- Code: ---#!/bin/sh
[ -z ${DISPLAY} ] && echo "Requires X" && exit 1
while true
do
/bin/sh -c "imlib2_grab /tmp/screenshot.png"
sleep 60
done
--- End code ---
Navigation
[0] Message Index
Go to full version