Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a remote server running "Ubuntu 10.04 Desktop". From it I want to run a script that walks through a list of websites and captures screenshots of them.

The script is working and thoroughly tested.

When I SSH to the server with ssh -X user@ip-adress I can run my script by calling ./myscript.py and everything will work OK.

I then modifed my crontab file and added...
59 17 * * * env DISPLAY=:0 /path/to/myscript.py
...as recommended by the Ubuntu WIKI.

I can see in the /var/log/syslog that my cron job is started, but it doesn't capture any screenshots.

When running env DISPLAY=:0 /path/to/myscript.py from the shell I get
No protocol specified
myscript.py: cannot connect to X server :0

If I ssh to the server without the -X option I only get the second row of the error: myscript.py: cannot connect to X server :0

What can I try now?

More details

  • I have run xhost +local: and checked the output of xhost to see that the option was set correctly.
  • If I run ls /tmp/.X11-unix/ the output is X0
  • The server only has one screen.

Thank you in advance!

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

You might want to consider running xvfb headless X server.

share|improve this answer
    
This works perfectly fine via SSH (without the -X option) but not via Cron. –  Christoffer May 15 '10 at 17:50
    
I was to quick... Misspelling :) It works perfect! –  Christoffer May 15 '10 at 17:54
    
excellent... i would still consider setting cron on your workstation, instead of using it on the server. –  cpbills May 15 '10 at 17:57
add comment

are you running the script via cron on the server?

also, it will not be :0 when you are doing X over ssh, it is going to be something completely different.

this would be much easier to do locally, or at least kick off locally from cron on the machine you have X running on.

when you log in, and can successfully kick off the script on the server, try echo $DISPLAY to see what it is set as. my sshd_config has X11DisplayOffset 10, which means it would be hostname:10.0

share|improve this answer
    
Yes, I run the cron on the server. I do not have access to this computer physically, just by SSH. Does it really make a difference if the user I ssh with is the same as the main user for the desktop machine? –  Christoffer May 15 '10 at 17:36
    
username should be insignificant. but running a gui from cron on a machine that you may not always be connected to seems backwards. i would want to launch the script from my computer, when it's on/connected. just something like * * * * * ssh username@hostname -X -c "/path/to/script.py" would be preferable, in your workstation's crontab –  cpbills May 15 '10 at 17:53
    
I made it work with xvfb-run /path/to/myscript.py :) As I said, the script captures screenshots of a list of websites, that's why I need X. –  Christoffer May 15 '10 at 17:56
    
i'm not saying you don't need X, i just think it would work better, launched from your computer, rather than on the server, because you may not be connected at all times, etc. –  cpbills May 15 '10 at 17:58
    
nevermind, it seems you don't even need to do it over ssh anymore, if i'm correct? since you don't need to display anything, xvfb is perfect for this, and cron can remain on the server with no problem... –  cpbills May 15 '10 at 18:01
add comment

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.