Cron python script not executing

I read a few posts about this, but I could not find help in them.

I have a python script that sends mail using smtplib. It works when called from the command line.

I have #!/usr/bin/python as the first line, and I can run it with /home/pi/ipsender.py or python /home/pi/ipsender.py .

My crontab */1 * * * * /home/pi/ipsender.py , but I also tried */1 * * * * python /home/pi/ipsender.py and */1 * * * * /usr/bin/python /home/pi/ipsender.py .

Running which python I get /usr/bin/pyhton and run python from the command line, which I can import and use smtplib just fine.

In /var/log/syslog I get:

 Nov 27 22:57:01 raspberrypi /USR/SBIN/CRON[3764]: (pi) CMD (python /home/pi/ipsender.py) Nov 27 22:57:01 raspberrypi /USR/SBIN/CRON[3763]: (CRON) info (No MTA installed, discarding output) 

And I guess No MTA ... is it just that Cron is not sending emails about what it is doing, or is it not?

How to run this script.

[change]

Script resolution

 -rwxr-xr-x 1 pi pi 551 Nov 27 22:37 ipsender.py 

[Edit2] Using prompts from D Read I get the following log

 starting Traceback (most recent call last): File "/home/pi/ipsender.py", line 7, in <module> ifconfig_output = sp.check_output(["ifconfig", "wwan0"]) File "/usr/lib/python2.7/subprocess.py", line 537, in check_output process = Popen(stdout=PIPE, *popenargs, **kwargs) File "/usr/lib/python2.7/subprocess.py", line 679, in __init__ errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory 

Offer me that there is something with the path. Although in /etc/crontab I have PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin and which ifconfig gives /sbin/ifconfig . So this should not be a problem?

+4
source share
2 answers

There are many gotchas with crons ... In the absence of MTA, see the output in a simpler way - try connecting it to a file:

 */1 * * * * /home/pi/ipsender.py > /home/pi/ipsender.log 2>&1 

Run your python file with print 'starting' to see if the python file is running in order.

+6
source

Try saving the STDOUT and STDERR script:

 */1 * * * * /home/pi/ipsender.py &> /tmp/ipsender.log 
+1
source

All Articles