I keep trying to run a cron job that executes a python script every minute. Having executed "which python", I set up the cron job as follows:
SHELL=/bin/bash
MAILTO=MyMac
PATH=bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
*/1 * * * * * /Users/MyMac/anaconda3/bin/python
/Users/MyMac/desktop/cron_test/test.py
Job's description is in one line and there is a new line character at the end of the definition.
I get the following error in /var/mail/MyMac
:
/bin/bash: AnacondaProjects: command not found
So I deleted:
SHELL=/bin/bash
and I got:
/bin/sh: MyMac: command not found
Then I tried all possible combinations of /usr/bin/python with or without lib, anaconda etc., with or without specifying PATH, SHELL, MAIL. Unfortunately, without success.
What am I doing wrong?
So here's the summary of what I did according to the pieces of advice I received:
I tried:
* * * * * env > /tmp/env.output,
first I got an error:
/bin/bash: /tmp/env.output: Permission denied,
so I made a cron Job as sudo. The path in the env.output is:
PATH= bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/Users/MyMac/AnacondaProjects
Finally I set my cronjob (as a normal user not as sudo) to:
SHELL=/bin/bash
[email protected]
PATH=bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/Users/MyMac/AnacondaProjects:/Users/MyMac/anaconda3/bin/python:/usr/bin/env
* * * * * /Users/MyMac/anaconda3/bin/python /Users/MyMac/desktop/cron_test/test.py
It still doesn't work. The python code is:
#!/usr/bin/env python
def main():
f = open("test.txt", "w+")
f.write("HELLO" + '\n')
f.close()
if __name__ == "__main__":
print("Print")
main()
I'm looking forward forward to get and try out new approaches.
Try doing this:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With