如何在linuxcrontab中运行python程序?

2024-10-02 10:28:10 发布

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

我在contab中添加了以下行

 1 * * * * /usr/bin/python /home/prkumar/Desktop/python/sample.py

我的样品.py文件

^{pr2}$

如果我在终端中运行python程序,它工作得很好,并且还将文本附加到示例.log文件。但是如果在crontab中添加程序,则没有响应。在

谢谢


Tags: 文件samplepy文本程序终端示例home
2条回答

更改python而不是/usr/bin/python,更改代码如下。在

1 * * * * python /home/prkumar/Desktop/python/sample.py >> /home/prkumar/Desktop/python/output.log

你需要纠正一下:

* * * * * /usr/bin/python /home/prkumar/Desktop/python/sample.py

每分钟都要跑。在

你的cron声明: 1 * * * * /usr/bin/python /home/prkumar/Desktop/python/sample.py

只会在每小时的第一分钟运行,例如09:01、10:01…等等。因此,您必须等待1小时才能看到结果。在

相关问题 更多 >

    热门问题