我在 ubuntu 环境中为 root 用户设置了一个 cronjob,如下所示,输入 crontab -e
I have set up a cronjob for root user in ubuntu environment as follows by typing crontab -e
34 11 * * * sh /srv/www/live/CronJobs/daily.sh 0 08 * * 2 sh /srv/www/live/CronJobs/weekly.sh 0 08 1 * * sh /srv/www/live/CronJobs/monthly.sh但是 cronjob 没有运行.我曾尝试使用 pgrep cron 检查 cronjob 是否正在运行,并给出进程 ID 3033.shell 脚本调用 python 文件并用于发送电子邮件.运行python文件没问题.它没有错误,但 cron 没有运行.Daily.sh 文件中包含以下代码.
But the cronjob does not run. I have tried checking if the cronjob is running using pgrep cron and that gives process id 3033. The shell script calls a python file and is used to send an email. Running the python file is ok. There's no error in it but the cron doesn't run. The daily.sh file has the following code in it.
python /srv/www/live/CronJobs/daily.py python /srv/www/live/CronJobs/notification_email.py python /srv/www/live/CronJobs/log_kpi.py 推荐答案我终于找到了解决方案.以下是解决方案:-
Finally I found the solution. Following is the solution:-
切勿在要通过 crontab 执行的 Python 脚本中使用相对路径.我做了这样的事情:-
Never use relative path in python scripts to be executed via crontab. I did something like this instead:- import os import sys import time, datetime CLASS_PATH = '/srv/www/live/mainapp/classes' SETTINGS_PATH = '/srv/www/live/foodtrade' sys.path.insert(0, CLASS_PATH) sys.path.insert(1,SETTINGS_PATH) import other_py_files
永远不要抑制 crontab 代码,而是使用邮件服务器并检查用户的邮件.这样可以更清楚地了解正在发生的事情.
Never supress the crontab code instead use mailserver and check the mail for the user. That gives clearer insights of what is going.
更多推荐
CronJob 未运行
发布评论