简体   繁体   English

将其放到Crontab后,Python脚本不起作用

[英]Python Script Doesn't Work After Put It On Crontab

I Have a python file named myfile.py that I want to run it every 1 minute. 我有一个名为myfile.py的python文件,我希望每1分钟运行一次。

When I use this command : 'python myfile.py' It Runs Correctly. 当我使用以下命令时:'python myfile.py'它可以正确运行。

But when I set time for it and put it in crontab it doesn't work. 但是,当我为它设置时间并将其放入crontab时,它不起作用。

What the hell is my problem? 我到底有什么问题?

my crontab -e configurations: 我的crontab -e配置:

1 * * * * python /home/myuser/Desktop/myfile.py 

You're missing a slash before home . home之前错过了一条斜线。

Try 尝试

1 * * * * python /home/myuser/Desktop/myfile.py 

您是否尝试过明确指定解释器路径?

1 * * * * /usr/bin/python /home/myuser/Desktop/myfile.py 

All these codes are correct. 所有这些代码都是正确的。 Consider this, perhaps your code is in the comment terminal. 考虑一下,也许您的代码在注释终端中。

You must remove the "#" mark from the beginning of the code. 您必须从代码开头删除“#”标记。

this is Comment 这是评论

    #1 * * * * python /home/myuser/Desktop/myfile.py 

this is Correct 这是对的

    1 * * * * python /home/myuser/Desktop/myfile.py 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM