开发者

Notification as a cron job

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


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.


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


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.


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

PATH=/bin:/usr/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/any/other/path

to your crontab file and see if it works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜