August 7, 2007

Script for GUI Linux Job Scheduling

       

If you need to start some gnu/linux app under console then great at command comes to the rescue, and it is easy to use.
But if you have a need to start some GUI app under KDE or Gnome than just issuing at command can't do it by itself.

I wanted to have some apps start on my desktop before I come to work and sit at the desk. I also close some apps at 16:15h as I work until 16h.
Closing apps is easy because I just used gnome-schedule which is a frontend to cron with command "pkill firefox" to shutdown firefox at given time.

Starting apps is a bit more tricky because all cron scripts are run under root privileges and I need an app to start under regular desktop user privileges. You can easily create cron tasks for regular users just by starting crontab command.

With some help from fedora-list mailinglist I got this script:

================== cut ===============

!/bin/bash

A script to create a script to run GAIM at 8:15 am.

script_file=~/start-gaim.sh

if [ -z $XAUTHORITY ] ; then
echo XAUTHORITY in not set!
exit 1
fi

if [ -z $DISPLAY ] ; then
echo DISPLAY is not set!
exit 1
fi

echo #!/bin/bash > $script_file
echo export XAUTHORITY=$XAUTHORITY >> $script_file
echo export DISPLAY=$DISPLAY >> $script_file
echo gaim >> $script_file
chmod +x $script_file

at -f $script_file 8:15 am

================== cut ===============

The only drawback is that I need to start this script every day under my username in order to have gaim start the next morning at 8:15am.
Do you have some idea how to make this work automatically every day? Do you have some other ideas how to do this in some other way? Please post your ideas as comments.