CronJob 未运行

编程入门 行业动态 更新时间:2024-10-26 20:27:54
本文介绍了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:-

  • 切勿在要通过 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 未运行

    本文发布于:2023-07-16 04:07:20,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1117680.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:CronJob

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!