Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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


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.