Linux: Gnome Scheduler (crontab):Error: Can't connect to X11 window server --- workaround

Asked by Carla Granberg

*** workaround:

Gnome Scheduler (crontab) does not support setting environment variables for recurrent tasks, but it will do soon. In the meantime, manually create a script that first defines DISPLAY variable and then calls the graphical application. Finally, you can create a recurrent task to launch the script.

This shell script now runs the Sikuli Script successfully when the task is launched from the crontab. The secret ingredient was the line "xhost local:" Without it, setting the DISPLAY variable did nothing.

#!bin/bash
DISPLAY=:0; export DISPLAY
xhost +local:
/usr/share/my-path/Sikuli-IDE/sikuli-ide.sh my-path/mydemo.sikuli.skl
#end script

-------------------------------------------------------------
Hi there,

I have built a Sikuli Script that runs successfully from command line in linux: OS Debian 6.0.2 GNOME Desktop Version 2.30.2

This is how I would run the script directly (using full paths) in my user session:
/usr/share/my-path/Sikuli-IDE/sikuli-ide.sh my-path/mydemo.sikuli.skl

Next I want to be able to run this script daily at a specified time using crontab (my username).

This https://help.ubuntu.com/community/CronHowto says that it is possible to run gui applications via cronjobs. This can be done by telling cron which display to use.

So I have followed the suggestion when specifying the job in the crontab (my username)

15 15 * * * env DISPLAY=:0 /usr/share/my-path/Sikuli-IDE/sikuli-ide.sh my-path/mydemo.sikuli.skl

However, this error occurs when the cronjob runs (the error is emailed from the cron-daemon):

--------------------------------------
No protocol specified
Exception in thread "main" java.lang.InternalError: Can't connect to X11 window server using ':0' as the value of the DISPLAY variable.
        at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
        at sun.awt.X11GraphicsEnvironment.access$100(X11GraphicsEnvironment.java:62)
        at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:166)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:142)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:186)
        at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82)
        at sun.awt.X11.XToolkit.<clinit>(XToolkit.java:112)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:186)
        at java.awt.Toolkit$2.run(Toolkit.java:849)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:841)
        at javax.swing.ImageIcon.<init>(ImageIcon.java:136)
        at javax.swing.ImageIcon.<init>(ImageIcon.java:155)
        at org.sikuli.ide.SikuliIDE.getIconResource(SikuliIDE.java:106)
        at org.sikuli.ide.SikuliIDE.<clinit>(SikuliIDE.java:85)
Could not find the main class: org.sikuli.ide.SikuliIDE. Program will exit.
-----------------------------------------

Do you have any other suggestions? Surely other folks must successfully execute their Sikuli Scripts via linux cronjobs.

Thanks.
Carla

ADDENDUM:
This is how I solved the issue. More reading tells me this:
-----------------
Gnome Scheduler (crontab) does not support setting environment variables for recurrent tasks, but it will do soon. In the meantime, manually create a script that first defines DISPLAY variable and then calls the graphical application. Finally, you can create a recurrent task to launch the script.
-----------------

This shell script now runs the Sikuli Script successfully when the task is launched from the crontab. The secret ingredient was the line "xhost local:" Without it, setting the DISPLAY variable did nothing.

#!bin/bash
DISPLAY=:0; export DISPLAY
xhost +local:
/usr/share/my-path/Sikuli-IDE/sikuli-ide.sh my-path/mydemo.sikuli.skl
#end script

---
cg

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

Thanks for the solution.

Revision history for this message
RaiMan (raimund-hocke) said :
#2

yes it is