WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Taking screen-shots under cron  (Read 2498 times)

Offline andydj

  • Newbie
  • *
  • Posts: 2
Taking screen-shots under cron
« on: April 01, 2016, 05:38:51 PM »
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




Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11619
Re: Taking screen-shots under cron
« Reply #1 on: April 01, 2016, 09:57:36 PM »
Hi andydj
Maybe you could run this modified version of windowshot.tcz:
Code: [Select]
#!/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
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.

Offline andydj

  • Newbie
  • *
  • Posts: 2
Re: Taking screen-shots under cron
« Reply #2 on: April 02, 2016, 04:20:24 AM »
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.


Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: Taking screen-shots under cron
« Reply #3 on: April 02, 2016, 04:31:41 AM »
Besides DISPLAY, root needs XAUTHORITY to be able to access tc's screen.
The only barriers that can stop you are the ones you create yourself.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11619
Re: Taking screen-shots under cron
« Reply #4 on: April 02, 2016, 09:11:32 AM »
Hi andydj
Code: [Select]
I'll try modifying it to capture the root window ... In that case it could be reduced to this:
Code: [Select]
#!/bin/sh

[ -z ${DISPLAY} ] && echo "Requires X" &&  exit 1
while true
do
/bin/sh -c "imlib2_grab /tmp/screenshot.png"
sleep 60
done