Issue
My crons are working normally, I tested it with simple file outputs and bash scripts, but nothing I have tried works when it comes to executing my python script.
So this is what I did.
as per usual I added a shebang to my script
#! /usr/bin/python3.5
&
chmod +x myPythonScript.py
I added it to crontab -e and tested on various ways.
examples:
* * * * * /path/to/myPythonScript.py
and just to be sure I even did the following
* * * * * python /path/to/myPythonScript.py
* * * * * python3.5 /path/to/myPythonScript.py
* * * * * /usb/bin/python /path/to/myPythonScript.py
* * * * * /usb/bin/python3.5 /path/to/myPythonScript.py
and even did */1 * * * * and other time tests.
Nothing worked, and if I write all of these outside the cron, everything works perfectly fine every time. I even changed the SHELL in the crontab -e knowing that it will not make any difference, but just to be sure, pasted the script in /etc/cron.hourly, nope, tried with /usr/bin/env python instead of the usual shebang, tried every other dumb thing, but it did not work out.
Cronjobs worked perfectly when running a bash script, I even ran a bash script to check if my python script is up and running and to notify me about that in a text log, and if its not, to restart it and also notify me about that, my text log was full of restarts and that was because it never ran the python script, so the cron was working obviously, because it ran the bash script.
Solution
When running cron, you should always write your standard out/err to a file to see whats happening. Don't trust mail because your mail server may/maynot be setup.
So, give this a try
* * * * * python /path/to/myPythonScript.py 1>/tmp/myPythonScript.out 2>/tmp/myPythonScript.err
After 1 minute check to see if the file /tmp/myPythonScript.{out,err} exist. This will give you a clear direction of what is happening.
Again, ALWAYS write your standard out/err
Answered By - NinjaGaiden