kcrontab has not only been developed for editing crontabs. The primary goal was to add functionality to the KDE desktop. This means that the program is also meant for use as scheduler for KDE. The following section describes how you can start KDE applications with cron.
KDE applications provide a nice and easy to use GUI wich gives them a superior usablility. The applications comunicate with the user through Windows, buttons, widgets, menus etc. This is nice and easy to understand but also generates a problem when using cron because cron will start every scheduled command in an own shell. This means the user has to tell cron on which X-Host and on which display to programm should be started. We will reach this goal by defining the host via xhost and by setting the environment variable $DISPLAY.
1st step:
We must define the apropriate X-host. On single workstations without a
connection to a local network this is almost ever localhost. In
general we could open a terminal every time we start KDE and type the
following command in order to define localhost as X-host:
xhost +localhost
Obviously this is not pretty straight forward. We want to automize things so
we go for a better alternative. Actually there are two possible solutions:
First of all we could give cron a shell-script instead of the application we
want to start. In this script we can call xhost and then the KDE
application. Here is an example:
#Script for calling the KDE app kcrontab via cron
#
xhost +localhost
/opt/kde/bin/kcrontab
#End
Some of you will says that this script is pretty much "brute force style".
You are right. For example one could/should also check in this script if the
call of xhost was successfull before calling the application. Feel
free to expand the script and please mail it to the authors!
The second possibility would be to call xhost every time the users starts KDE. For this we can create a link in the autostart folder on the desktop. In order to do this open your autostart folder and select FILE/NEW/PROGRAM from the menu-bar. We will call this link xhost.kdelnk. The link will be created.
the autostart folder with xhost.kdelnk
Now we click the xhost icon with the right mouse-button and select PROPPERTIES. Select the EXECUTE section and enter xhost +localhost in the appropriate field (see image for example). Now xhost will be called every time KDE starts.
The xhost.kdeln proppertiesk
2nd step:
Now we have to make shure that the environment variable $DISPLAY is
set correctly. We do this in kcrontab. Select the menu EDIT/EDIT
VARIABLES from the menu bar. Enter DISPLAY in the
Variable: field and localhost:0.0 in Value:. Now KDE
applications can be started via cron.
Setting the DISPLAY-variable in kcrontab
3rd step:
Now we are ready for testing the setup. We can do this by creating a
test-entry in kcrontab. We will try to start kcrontab by cron.
In order to find misconfigurations it will be helpfull to open a terminal
with the contents of /var/log/messages/. Doing this is easy: open a
terminal (kvt for example), switch to root if necessary and type:
tail -f /var/log/messages
Everything kcrontab and cron do will now be displayed. When
the scheduled time for our command is reached, cron will try to run it. This
will be logged. If no window opens (nothing happens) you still have a
problem.
a terminal with tail -f /var/log/messages helps you
debugging
Note:
All steps have been tested by the authors. If you encounter problems on your
system or you have to do things diferently please give us a hint. Also we
will be glad for any hints which make the usages/configuration easier. The
decribed method is certainly not very "smooth".