1

I've got a python file called color.py that if I run using python color.py will work on a file. I can run it okay from the terminal but it doesn't get called from crontab. I've used chmod +x color.py to try and make it executable.

The py file does start with

#!/usr/bin/env python

and the cron command is

*/1 * * * * /root/images/color.py
5
  • here are some hints: stackoverflow.com/questions/8727935/…. I think you have to change /usr/bin/env to /usr/bin/python (use 'which python' to discover where your python is) Commented Jul 14, 2017 at 22:04
  • Have you tried to run it as /root/images/color.py? Commented Jul 14, 2017 at 22:04
  • @Rawing I can run it from images folder using python color.py Commented Jul 14, 2017 at 22:27
  • @SamuelM. That's not what I asked - can you run it as /root/images/color.py? Commented Jul 14, 2017 at 22:29
  • @anneb tried changing to /usr/bin/python and chmod a+x hasn't worked Commented Jul 14, 2017 at 22:32

1 Answer 1

1

First check if following command works by running as user root (su or sudo):

/usr/bin/python /root/images/color.py

If that works, then edit crontab to:

*/1 * * * * /usr/bin/python /root/images/color.py

How do you check if the cron job succeeds or not?

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

11 Comments

the command works and it deletes a file(s) that's how I know the task's done
do you reference the file to be deleted by its full path? Not delete 'myfile' but something like delete '/root/images/myfile' ?
using os.remove(filename) @anneb
is ' filename' full path or not? If it is 'myfile' it will only work if you explicitly change the working dir to the directory containing the file, if it is '/root/images/myfile' then that should be ok
I've edited to this been more than a minute but the file still is there, I know if I run python color.py it's going to colour the image make a new file and delete the old one.
|

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.