1

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?

1

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

9 Comments

I have followed this and it still will not run with cron
Is the file executable on the system? (via chmod ?)
When you ls -al on the directory what are the permissions on that file?
I did make it executable with chmod a+x file.py, and when I ls al it says -rwxr-xr-x
In your example above it looks like you are just trying to "run" the file. You need actually call the python executable, and pass it an argument that points to your file. */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.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.