Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to take a screenshot every five minutes with 'scrot'. To do this over a SSH connection, I can either run

ssh -X user@server
while true; do scrot -z; sleep 300; done

OR (after manually check of folder name in /var/run/gdm/auth-for-XXX-YYY/database)

ssh user@server
export DISPLAY=:0
export XAUTHORITY=/var/run/gdm/auth-for-user-wUM1sV/database
while true; do scrot -z; sleep 300; done

But if I want to do this as a cron job, I will automatically need to map the environment variable XAUTHORITY to the random folder in /var/run/gdm/. According to this post How do I create the .Xauthority file? this mapping is done automatically, but that is not the case for cron jobs I guess and apparently not for SSH sessions if X forwarding is not used.

Does anyone have a suggestion on how to create this cron job?

share|improve this question

1 Answer 1

Assuming your user is logged in with an X session, and is the first session, it will get the display number 0, otherwise try to find out the display number the user is running. Try to put this in the user's crontab

*/5 * * * * DISPLAY=:0 /usr/bin/scrot
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.