Sunday, December 25, 2016

linux - Screenshot cron job not working


I've been searching all over the internet for an aswer to this but can't seem to find anything that works for me.


I want to run a cron job that automaticly takes a screenshot every minute. The script look like this:


#!/bin/bash
cd /home/ville/Skrivbord/screenshot
import -display :0 -win root screenshot.jpg

The code works fine when manually executed but does not work when i run it as a cron job.


The cron file look like this:


* * * * * /root/bin/screen.bash &> /dev/null
* * * * * /root/bin/syncdata.bash

The other task, syncdata works fine.


Here are some of the things i've tried without success:


Change permissions on /root/bin/screen.bash and /home/ville/Skrivbord/screenshot to 777 and change owner to root.


Change filename to screen.sh (maybe there's no difference between .bash and .sh?)


Change the import line to "import -win root screenshot.jpg" and "import -display :0.0 -win root screenshot.jpg".


Added the code:


# Set display to :0 if it's not already set.
: ${DISPLAY:=:0}
export DISPLAY

One time above the existing code in screen.bash and one time below.


Changed the line in cron to "* * * * * export DISPLAY=:0 && /root/bin/screen.bash".


Nothing works!


Please help me


Answer



Programs started by the cron daemon do not have the authentication data needed to connect to your X server. Try putting something like this in your ~/.xprofile:


if [ "$XAUTHORITY" ]; then
cp -f "$XAUTHORITY" ~/.Xauthority
fi

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...