Cron python脚本未执行 [英] Cron python script not executing

查看:200
本文介绍了Cron python脚本未执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了几个帖子,但我找不到帮助他们。

I have read a few posts on this but I could not find help in them.

我有一个python脚本使用smtplib发送邮件。

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

我有#!/ usr / bin / python 作为第一个行,可以使用 /home/pi/ipsender.py python /home/pi/ipsender.py

I have #!/usr/bin/python as the first row and can run it both using /home/pi/ipsender.py and python /home/pi/ipsender.py.

我的crontab是 * / 1 * * * * /home/pi/ipsender.py 尝试了 * / 1 * * * * python /home/pi/ipsender.py * / 1 * * * * / usr / bin / python /home/pi/ipsender.py

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

执行 which python code> / usr / bin / pyhton 并从命令行运行python我可以导入和使用smtplib很好。

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

/ var / log / syslog 我得到:

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)

...

如何运行此脚本

脚本的权限是

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

[Edit2]
使用D读取的提示我获得以下日志

Using the tip from D Read I'm getting 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

建议我有路径的东西。虽然在 / etc / crontab 我有 PATH = / usr / local / sbin:/ usr / local / bin:/ sbin:/ bin: usr / sbin:/ usr / bin 其中ifconfig 提供 / sbin / ifconfig 。所以这不应该是一个问题权利?

Suggesting to 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 that should not be a problem right?

推荐答案

有很多getchas与crons ...在没有MTA ,请看输出一个更简单的方法 - 尝试将其管道到一个文件:

There are lots of gotchas with crons... In the absence of the MTA, see the output an easier way - try piping it to a file:

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

code> print'starting'查看python文件是否开始执行ok。

Start your python file off with a print 'starting' to see if the python file starts to execute ok.

这篇关于Cron python脚本未执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆