【问题标题】:cron job error: sh: 1: <pkg>: not foundcron 作业错误:sh:1:<pkg>:未找到
【发布时间】:2014-05-23 16:47:18
【问题描述】:

我正在为我的 python django 项目使用覆盖模块。现在我想使用 cron 作业邮寄我的覆盖率报告。为此,我为运行单元测试用例创建脚本并在附件中发送报告。如果我手动运行该文件,这工作正常。但是使用 cron 作业我在登录日志文件时遇到此错误。

sh: 1: coverage: not found

我的运行单元测试和发送邮件的文件: coverage_report.py

def run_test():
    print 'before running'
    try:
        print commands.getoutput("cd project_path && coverage run --source='.' manage.py test")
    except:
        print "Error in run_test"
    print 'done running'

def generate_report():
    try:
        commands.getoutput('cd /tmp/ && rm report.txt')
        commands.getoutput('cd project_path && coverage report */*.py >> /tmp/report.txt')
    except:
        print "Error in generate report"
def send_mail():
    send_email('Coverage Report', 'This is coverage report for this week ', ['gauravnagpal2002@gmail.com'],'plain',['/tmp/report.txt'])


def main():
    run_test()
    generate_report()
    send_mail()
    print "Mail send successfully."

if __name__ == '__main__':
     main()

如果我手动运行此文件,它工作正常并以 txt 格式发送报告。但是如果我使用 cron 作业运行这个文件,它会发送空白文件。 我的玉米作业语法:

21  6  *  *  *  python <project_path>/scripts/coverage_report.py >> /tmp/coverage_report.log

运行此文件后生成的文件/tmp/coverage_report.log

before running

sh: 1: coverage: not found
done running
Mail send successfully.

请帮忙。

【问题讨论】:

  • PATH 问题。 coverage 不在 Cron 的路径中。您的 shell 脚本应该在您的脚本中包含 export PATH=...
  • @JamesMills 感谢您的评论我得到了解决方案。是的,路径是问题所在。我现在给出完整的覆盖路径,即 /usr/local/bin/coverage 而不是覆盖。 :)

标签: python django cron crontab


【解决方案1】:

PATH 问题。

coverage 不在您的 cron 作业路径中。

你的 shell 脚本应该包括:

export PATH=...

【讨论】:

    猜你喜欢
    • 2016-05-02
    • 2017-02-10
    • 2021-11-25
    • 1970-01-01
    • 1970-01-01
    • 2016-08-21
    • 2021-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多