通过crontab调度python脚本

2024-09-27 00:13:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用以下代码向crontab添加一个python脚本:

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

文件是可执行的python脚本。在

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

file2.py显然也通过crontab执行。在

由于某些原因,file.py不能通过crontab工作,但如果我通过命令行运行它,它就可以工作了。在


Tags: 文件代码py脚本信息数据库进程mysql
1条回答
网友
1楼 · 发布于 2024-09-27 00:13:09

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

请确保python exec x的每个文件.py)在

相关问题 更多 >

    热门问题