Crontab not running python script on Windows Subsystem for Linux (WSL)

3872 views python
4

I am trying to run a python script on Linux via WSL.

First of all I run service --status-all and both atd and cron are marked as [+]. Just to make sure that it works i typed in crontab -e the following:

*/2 * * * * /home/myname/Task_scripts/example.sh

This is what the script file example.sh looks like:

#!/bin/sh
echo "Hello World - Generated every 2 mins" >> ~/hello1.txt

The file indeed runs as set every 2mins so everything fine so far.

Let's move to the Python part now. I follow the exact same process i.e. crontab with a script and cannot get it run no matter what. In specific these are the two alternatives (among the many i tried) that i expected to work but apparently do not. FYI I am using an anaconda environment.

Alternative 1:

What i have in crontab: */2 * * * * /home/myname/Task_scripts/email_example.sh How the file looks like:

#!/bin/sh
/home/myname/anaconda3/envs/py36env/bin/python /home/myname/Production/example_email.py

Here are the rights in the .py file after running chmod +x email_example.sh:

-rwxrwxrwx 1 myname myname 99 Nov 7 21:26 email_example.sh

Alternative 2:

Set the crontab as follows:

*/2 * * * * /home/myname/anaconda3/envs/py36env/bin/python /home/myname/Production/example_email.py

The rights on the .py are same as above.

Executing manually the:

/home/myname/anaconda3/envs/py36env/bin/python /home/myname/Production/example_email.py

runs as it is supposed to do.

answered question

1 Answer

12

have you make the example_email.py as an executable file?

chmod +x /home/myname/Production/example_email.py

posted this

Have an answer?

JD

Please login first before posting an answer.