0

My cron runs ok when it's set up like this:

* * * * * usr/local/bin/python3 /Users/username/path/to/my/script1.py
* * * * * bash -c -l "/Users/username//path/to/my/script2.sh"

When I run the above scripts manually in terminal like this, it also works:

usr/local/bin/python3 /Users/username/path/to/my/script1.py
sh /Users/username//path/to/my/script2.sh

However, when I try to run both scripts as a subprocess in a parent.py script scheduled as cron job then it won't work and throw this error:

/bin/sh: usr/local/bin/python3: No such file or directory

My parent.py code:

import subprocess

subprocess.run('usr/local/bin/python3 /Users/username/path/to/my/script1.py && sh /Users/username//path/to/my/script2.sh', shell=True)

however, when I run parent.py manually in terminal like this, it works fine:

usr/local/bin/python3 /Users/username/path/to/my/parent.py

I've tried adding #!/usr/local/bin/python3 to my parent.py but this didn't help.

Could someone help with this? Thanks in advance.

3
  • 1
    Can python actually be located in usr/local/python3? If you check the command line then you need a preceding forward slash to access /usr/local. Commented Jun 19, 2020 at 13:26
  • adding slash actually solved the issue! thanks! Commented Jun 20, 2020 at 10:45
  • Great, I've added as answer. Commented Jun 20, 2020 at 15:55

1 Answer 1

1

You are missing a slash before usr/local/python3!

It should be /usr/local/python3

See this for more details.

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

Comments

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.