简体   繁体   English

使用Cron Job运行Python脚本时发出Ping问题

[英]Issue Pinging with Python Script Running as Cron Job

I wrote a Python script to periodically ping network devices to ensure they are connected. 我编写了一个Python脚本来定期ping网络设备,以确保它们已连接。 My pinging code is as follows: 我的ping代码如下:

response = os.system('ping -q -c 5 ' + ip_address)

This works fine when I run it manually, however, when I run it as a cron job I get the response: 当我手动运行它时,它可以很好地工作,但是,当我将其作为cron作业运行时,会得到响应:

sh: ping: command not found

I have tried having the cron job run the program as both a packaged application which I created using pyinstaller, and directly as a Python script. 我尝试过让cron作业将程序作为我使用pyinstaller创建的打包应用程序运行,并直接作为Python脚本运行。 Regardless, I get the same error for both (and the correct result when I run either manually). 无论如何,我都会遇到相同的错误(以及手动运行时的正确结果)。

通过将“ / sbin / ping”指定为命令来修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM