Cron task python script not working

瘦欲@ 提交于 2019-12-25 02:57:34

问题


I have a python script I want to fire off every night at midnight. I'm using cron scheduler right now to do so, however, I can't figure out why it's not working. For now, I've been using close times (within the next minute or so) to test the cronjob, but I will ultimately want it to work for midnight.

Here is what I put in my crontab file (to run for 2:43pm), hosted on my ubuntu machine:

43 14 * * * root /home/grantmcgovern/Developer/Projects/StudyBug/Main.py

I even put the:

#!user/bin/python 

on top of all the .py files.

I also did:

chmod +x "scriptname".py

For each of the .py files and still no luck. Am I missing something blatantly obvious? I should note, this is my first time playing with cron tasks.


回答1:


From your current crontab file, you're basically running root /home/grantmcgovern/Developer/Projects/StudyBug/Main.py every time.

If you want to run it as root, use sudo crontab -e and put 43 14 * * * /usr/bin/python /home/grantmcgovern/Developer/Projects/StudyBug/Main.py instead.




回答2:


I think it is looking for the command "root" so the syntax is wrong, so it should be this...

43 14 * * * /home/grantmcgovern/Developer/Projects/StudyBug/Main.py

If you need it to run as root then I think you can use su like this:

43 14 * * * su root -c "/home/grantmcgovern/Developer/Projects/StudyBug/Main.py"

If you add it to the system crontab then I think it will anyway.



来源:https://stackoverflow.com/questions/23160307/cron-task-python-script-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!