CronJob 未运行 [英] CronJob not running

查看:30
本文介绍了CronJob 未运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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:-

  1. 切勿在要通过 crontab 执行的 Python 脚本中使用相对路径.我做了这样的事情:-

  1. 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 未运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆