@reboot cronjob 未执行 [英] @reboot cronjob not executing

查看:39
本文介绍了@reboot cronjob 未执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Python 脚本,它只是编写一些文本并将其保存到文件中

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();

我想在启动时通过 CRON 执行这个脚本.所以我使用

I want to execute this script at startup via CRON. So I edit the crontab listing by using

>crontab -e

我的整个 crontab 看起来像:

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

这是文件所在的位置,文件有执行权限.我可以从命令行将文件作为脚本运行没有问题.然而,当我重新启动机器时,没有生成任何文件.我试图了解原因,并尝试使用 crontab 条目.

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

这也不起作用.

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 之前/之后安装.我会尝试:

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 

但这也没有用.

运行:

pgrep cron

返回 957

推荐答案

Mark Roberts 指出了我做错的一些事情.

Mark Roberts pointed out a few things I'd done wrong.

也就是这里的空格

MAIL = root
HOME = /

去掉那些空格..

接下来,将 Cron 配置固定为每分钟发送电子邮件......而不是我所拥有的:

Next, having Cron configuration fixed to email every minute.. instead of what I had :

*/1 * * * * /home/user/tester.py

在我看来 Lubuntu 不支持 @Reboot Cron 语法.

Seems to me Lubuntu doesn't support the @Reboot Cron syntax.

这篇关于@reboot cronjob 未执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆