简体   繁体   中英

Trouble executing a python 3 script every minute with cron

I am attempting to run a python 3 script every 1 minute using cron on a raspberrypi 3, for testing, where eventually it will just be run once a day.

To start, I made a new cron job using: sudo crontab -e , and typed in the following code for a once a minute job:

*/1 * * * * /home/pi/folder/file.py

Then I saved and closed and waited. My python script emails me text when executed, so I should have seen an email come in. It runs fine (and emails me) when I execute it manually outside of cron.

So, what am I doing wrong with cron for it not to run? And do I need to make the python file executable or something with chmod ?

Possible duplicate of Execute python Script on Crontab

EDIT: Adding comment here since the comment box mangled my formatting.

In your example above it looks like you are just trying to "run" the file. You need to call the python executable, and pass it an argument that points to your file.

From the StackOverflow comment mentioned above look at this crontab entry:

*/2 * * * * /usr/bin/python /home/souza/Documets/Listener/listener.py

Take a look at the first part of the command /usr/bin/python this is pointing to the python executable not just to the .py file you want to run.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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