Take the 2-minute tour ×

I coded a python application which was running OK as a cron job. Later I added some libraries (e.g. pynotify and other *) because I wanted to be notified with the message describing what is happening, but it seems that cron can't run such an application.

Do you know some alternative how to run this application every five minutes? I'm using Xubuntu.

  • import gtk, pygtk, os, os.path, pynotify

I can run the application without cron without problems.

Cron seems to run the application but it won't show the notification message. In /var/log/cron.log there are no errors. The application executed every minute without problems.

my crontab: */1 * * * * /home/xralf/pythonsrc/app

thank you

share|improve this question
Details details. What are the errors you get? –  Noufal Ibrahim May 31 '11 at 18:20
@Nofaul Ibrahim Detail added. –  xralf May 31 '11 at 18:53
add comment

4 Answers

If your python script runs fine by itself and only fails in cron, then most likely the paths to the libraries are not set in cron. Here's an example from one of my cronjobs where I add the path to cron before executing the file

00 12 * * * LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib && export LD_LIBRARY_PATH && /path/to/my/script

You'll have to replace the paths above with the respective paths to your libraries.

share|improve this answer
add comment

If the cron job runs as "you", and if you set the DISPLAY var (export DISPLAY=:0) you should have no issues.

share|improve this answer
This didn't help. –  xralf May 31 '11 at 19:03
You gotta be more specific. Do you have any errors? If you don't have any errors, do you have a mail agent delivering cron errors to you? Does it silently fail? –  EightyEight Jun 2 '11 at 17:26
@EightyEight Look at the updated question. –  xralf Jun 2 '11 at 18:22
Basically it seems that the environment between your running session and cron is somehow different. For example your app may be determining (via the library support) that you can't run X apps or something like that. Drop into shell and do 'echo $DISPLAY' for instance. What does that say? –  EightyEight Jun 5 '11 at 18:57
echo $DISPLAY shows :0.0 If I call export DISPLAY=:0 it shows :0 –  xralf Jun 5 '11 at 19:03
show 3 more comments

I don't see any problem in cron job with pynotify? What is the error you are getting?

Can you run your python code separately to check whether your python code is working really well but only fails with cron?

Celery is distributed job queue & task manager written in Python but it may be too much for your needs.

Supervisord also can do some sort of cron task if you know that your program shall close in 5 minutes. So you can configure supervisord to start the task soon after. None of them are not easier like cron job.

share|improve this answer
I added more info to the question. –  xralf May 31 '11 at 18:46
He's importing GTK, if his cron job tries to run a GTK application, it'll fail because the cron daemon doesn't have access to the X server. –  nos May 31 '11 at 18:46
add comment

Your most likely problem is a pathing issue. Cron does not have user paths unless you specifically set it up. So if your libraries are installed in non standard locations or user accounts, cron will need full paths or else you need to set the path variable in your crontab file.

Add the line


to your crontab file and see if it works.

share|improve this answer
add comment

Your Answer


