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

3872 views python

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/

This is what the script file looks like:

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/ How the file looks like:

/home/myname/anaconda3/envs/py36env/bin/python /home/myname/Production/

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

-rwxrwxrwx 1 myname myname 99 Nov 7 21:26

Alternative 2:

Set the crontab as follows:

*/2 * * * * /home/myname/anaconda3/envs/py36env/bin/python /home/myname/Production/

The rights on the .py are same as above.

Executing manually the:

/home/myname/anaconda3/envs/py36env/bin/python /home/myname/Production/

runs as it is supposed to do.

answered question

1 Answer


have you make the as an executable file?

chmod +x /home/myname/Production/

posted this

Have an answer?


Please login first before posting an answer.