从crontab运行时,调用“arp”的Python脚本会产生错误

2024-09-30 12:33:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我的服务器

Linux dhcpns 3.19.0-28-generic #30-Ubuntu SMP Mon Aug 31 15:52:51 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

我的Python脚本

^{pr2}$

当我从命令行运行脚本时,它会产生预期的输出。 但是,当我从crontab -e调用脚本(很明显,将输出重定向到文件)时,脚本失败。在

日志

Sep 28 18:36:01 dhcpns testarp.py[9984]: OS system call failed.
Sep 28 18:36:01 dhcpns testarp.py[9984]: Traceback (most recent call last):
Sep 28 18:36:01 dhcpns testarp.py[9984]: File "/home/ubuntu/testarp.py", line 23, in <module>
Sep 28 18:36:01 dhcpns testarp.py[9984]: lstArp =  getarp()
Sep 28 18:36:01 dhcpns testarp.py[9984]: File "/home/ubuntu/testarp.py", line 10, in getarp
Sep 28 18:36:01 dhcpns testarp.py[9984]: arp = sp.Popen(cmd, stdout=sp.PIPE, stderr=sp.PIPE)
Sep 28 18:36:01 dhcpns testarp.py[9984]: File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
Sep 28 18:36:01 dhcpns testarp.py[9984]: errread, errwrite)
Sep 28 18:36:01 dhcpns testarp.py[9984]: File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child
Sep 28 18:36:01 dhcpns testarp.py[9984]: raise child_exception
Sep 28 18:36:01 dhcpns testarp.py[9984]: OSError: [Errno 2] No such file or directory

世贸基金会? 我错过了什么?在


Tags: inpy脚本homeubuntulinuxlinecall
1条回答
网友
1楼 · 发布于 2024-09-30 12:33:19

通过cron运行的命令继承不同的环境。特别是,PATHenvvar可能不同。要解决此问题,请在Python脚本中指定arp程序的完整路径,或在相应的crontab中显式配置PATH

PATH=/bin:/usr/bin:/path/where/arp/lives

相关问题 更多 >

    热门问题