首页 文章

通过crontab安排python脚本

提问于
浏览
1

我正在尝试使用以下行向crontab添加python脚本:

0 * * * * /pathtoexecutable/file.py
0 0 1 * 1 /pathtoexecutable/file2.py

文件是可执行的python脚本 .

file.py 进一步启动大约15个子进程,这些子进程将信息存储在MySQL数据库中 .

显然, file2.py 也可以通过crontab执行 .

出于某种原因 file.py 无法通过crontab工作,但如果我通过命令行运行它可以工作 .

1 回答

  • 1

    1)捕获你的脚本的输出和错误: .

    0 * * * * /pathtoexecutable/file.py &>> /path/some/log.txt
    0 0 1 * 1 /pathtoexecutable/file2.py &>> /path/some/log2.txt
    

    2)确保每个python文件都以shebang开头:#! / usr / bin / env python

    3)确保每个python文件都有一个exec模式(chmod x file.py)

相关问题