← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #166990]: running Sikuli Script from crontab gives Error: Can't connect to X11 window server using ':0

 

Question #166990 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/166990

Description changed to:
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 Schedule (crontab) does not support setting environment variables for recurrent tasks ... In the meantime, manually create a script that first defines DISPLAY variable and then calls the graphical application.

This shell script  runs the Sikuli Script successfully from the crontab.
The secret ingredient was "xhost local:" --

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

---
cg

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.