Crontab执行,但什么也没发生(python文件)
我设置了一个crontab文件,每分钟执行一个python文件,尽管它声明它已执行,但没有生成任何文件 crontest1.py文件包含:Crontab执行,但什么也没发生(python文件),python,cron,Python,Cron,我设置了一个crontab文件,每分钟执行一个python文件,尽管它声明它已执行,但没有生成任何文件 crontest1.py文件包含: #!/usr/local/bin/python # -*- coding: utf-8 -*- if __name__ == '__main__': f = open('/APPS/CronRun/crontest/dummy1.txt','w') f.write('hello world it is a file') f.clo
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
if __name__ == '__main__':
f = open('/APPS/CronRun/crontest/dummy1.txt','w')
f.write('hello world it is a file')
f.close()
Crontab文件:
# /etc/crontab - root's crontab for FreeBSD
#
# $FreeBSD: release/10.0.0/etc/crontab 194170 2009-06-14 06:37:19Z brian $
#
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
#
#minute hour mday month wday who command
#
* * * * * root /APPS/CronRun/crontest/crontest1.py
11 11 * * * root /usr/bin/find /APPS/* | grep python | grep core | xargs rm
14 14 17 * * root /APPS/CronRun/Report/report.py
执行crontab,但不显示任何文件
我尝试了一个简单的date>>datelog.txt
它通过crontab工作,但是python文件似乎没有执行
如果从shell手动执行而不是通过crontab执行,则python文件可以工作
我已经尝试在crontab文件中显式地声明:python/APPS/CronRun/crontest/crontest1.py,但这不起作用
我以前添加了cron作业,这些作业工作正常,每天都能执行,没有任何问题
e、 g
请尝试以下代码:
if __name__ == '__main__':
像这样:
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
f = open('/APPS/CronRun/crontest/dummy1.txt','w')
f.write('hello world it is a file')
f.close()
也许“crontest1.py”是由crontab作为模块执行的,而不是“main”
如果这没有帮助,请尝试更新Python
Python3.1.x及更低版本
可能是原因。您重新启动了系统/重新启动了cron吗?我只需要在这里澄清一下:我使用了cron,但仅用于可执行文件或shell脚本。cron也可以执行Python脚本吗?我的意思是,它不需要像python abc.py这样的命令吗?@kiner_shah如果文件是可执行的
chmod+x file.py
,那么一切都很好-它只执行program@nch如果将打印(“hello world”)
语句放在if
块之外的某个位置,会发生什么情况,如果您手动运行它并且从任何地方看到cron,是否会出现这种情况output@nch,您可以尝试将结果记录在单独的文件中。如下所示:/APPS/CronRun/makelist/list.py>/APPS/CronRun/makelist/log\u python\u脚本
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
f = open('/APPS/CronRun/crontest/dummy1.txt','w')
f.write('hello world it is a file')
f.close()