Run graphical program from crontab

Deron Meranda deron.meranda at gmail.com
Thu Aug 11 19:38:59 UTC 2005


On 8/11/05, Mattia <mattia at sinapto.net> wrote:
> I'm trying to solve a problem, but I can't guess the solution: I have
> written a small program, with a graphical interface, and I would like to
> launch it from the crontab, so that it would appear on my desktop.

First make sure it is cron that you really want, that means running
the program based upon time, and not when you log in.  Also doing
so will require that your X session actually be logged in and running.
And since cron will start it repeatively, you might need to put some
logic in to prevent multiple copies of the program from running
(unless that's what you want).

> I'v tried also to launch the program from a bash script, which is then
> executed from thr crontab. This is the script:
> 
> #!/bin/bash
> export DISPLAY=localhost:0.0
> /home/esperimenti/tcltk/test3.tcl >> /root/output 2>> /root/errori

You probably want to use DISPLAY=:0.0 instead.  Otherwise it's going
to require that X host-based authentication is set up, perhaps by
using MIT magic cookies.  By using :0.0 instead it will connect
directly to your X server (assuming your cron is running as the same
machine and with the same user as your display).

Also note that the environment of processes started by cron is
usually quite thin.  You may need to set even more variables in
your wrapper script.  For instance adding /usr/X11R6/bin to your
PATH.  Or maybe your XAUTHORITY variable.  Do an "env" from
a normal shell and see what variables you think you may need.

If you want your wrapper script to first check that your X session
is running before starting your primary program, you might
do something like:

DISPLAY=:0.0
PATH=$PATH:/usr/X11R6/bin
export DISPLAY PATH
dpyinfo >/dev/null >&2
if [ $? -ne 0 ] ; then
    exit 0   # display not available
fi
.....continue on....


I don't know if there are any SElinux concerns here.  I don't
think so, but if you still can't get it to work and SElinux is
enabled, check your log files and look for avc messages.

Deron Meranda




More information about the fedora-list mailing list