@reboot cronjob未执行 [英] @reboot cronjob not executing
问题描述
我有一个Python脚本,它只是写一些文本并保存到一个文件中。
#! / usr / bin / python3
def main():
filename ='/home/user/testHello.txt'
openfile = open(filename,w)
print (Hello CRON,file = openfile)
如果__name__ ==__main__:
main();
我想在启动时通过CRON执行这个脚本。所以我使用
编辑crontab列表。> crontab -e
pre>
我的整个crontab看起来像:
SHELL = / bin / bash
PATH = / sbin:/ bin:/ usr / sbin:/ usr / bin
MAILTO = root
HOME = /
#run-parts
1 * * * * /home/user/tester.py
@reboot /home/user/tester.py
这是文件的位置,并且该文件具有执行权限。我可以运行文件没有问题作为脚本从命令行。然而,当我重新启动机器,没有生成文件。我试图理解为什么,并玩crontab条目。
@reboot / usr / bin / python3 / home / user / tester.py
这也无效。
编辑:
ps aux | grep crond
给我
user 2259 0.0 0.0。 9436 948 pts / 0 S + 23:39 0:00 grep --color = auto crond
不确定如何检查crond是否正在运行,或者如果有问题的用户在CRON之前/之后安装。我将尝试:
sudo crontab -e
$ p $
运行:
pgrep cron
返回957
解决方案Mark Roberts指出了一些我做错了的事情。
也就是这里的空间
MAIL = root
HOME = /
删除这些空格。
接下来,将Cron配置固定为电子邮件每分钟..而不是我有:
* / 1 * * * * /home/user/tester.py
看来我Lubuntu不支持@Reboot Cron语法。
I have a Python script which simply writes some text and saves it to a file
#! /usr/bin/python3 def main(): filename = '/home/user/testHello.txt' openfile = open(filename,"w") print("Hello CRON", file = openfile) if __name__ == "__main__": main();
I want to execute this script at startup via CRON. So I edit the crontab listing by using
>crontab -e
My entire crontab looks like :
SHELL = /bin/bash PATH = /sbin:/bin:/usr/sbin:/usr/bin MAILTO = root HOME = / # run-parts 1 * * * * /home/user/tester.py @reboot /home/user/tester.py
This is the location of the file, and the file has permissions to execute. I can run the file no problem as a script from the commandline. Yet when I restart the machine, no file is generated. I am trying to understand why, and played around with the crontab entry.
@reboot /usr/bin/python3 /home/user/tester.py
This didn't work either.
Edit:
ps aux | grep crond
gives me
user 2259 0.0 0.0. 9436 948 pts/0 S+ 23:39 0:00 grep --color=auto crond
I am unsure how to check if crond is running, or if the user in question is mounted before/after CRON. I'll try with:
sudo crontab -e
but that hasn't worked either.
Running:
pgrep cron
returns 957
解决方案Mark Roberts pointed out a few things I'd done wrong.
Namely, the spaces here
MAIL = root HOME = /
Get rid of those spaces..
Next, having Cron configuration fixed to email every minute.. instead of what I had :
*/1 * * * * /home/user/tester.py
Seems to me Lubuntu doesn't support the @Reboot Cron syntax.
这篇关于@reboot cronjob未执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!