AWS Greengrass子进程命令不起作用

时间:2017-09-10 11:37:20

标签: python linux amazon-web-services raspberry-pi

我在我的Raspberry Pi 3设备上运行greengrass,我遇到了一些问题,Raspberry Pi无法正确解析某些路由器的DNS并执行解决方法我运行以下python脚本:

import urllib2
import subprocess
import platform
import time

def internet_on():
    try:
        output = subprocess.check_output("ping -{} 1 {}".format('n' if platform.system().lower()=="windows" else 'c', "a2jcwnhq2encoj.iot.us-east-1.amazonaws.com"), shell=True)

    except Exception, e:
        print "internet is off"
        return False
    print "internet is on"
    return True

def fire_dns_corrector():
    if platform.system().lower() != "windows":
        print "running resolver"
        bash_command = "bash /home/pi/nameresolution.sh"
        print bash_command
        subprocess.Popen(bash_command.split(), stdout=subprocess.PIPE)
        time.sleep(5)
    else:
        print "cannot resolve internet while running windows"

当我从命令行运行python as-is时,上面的代码工作正常,但是当通过Lambda函数运行时会崩溃greengrass核心。

我在crash.log中遇到以下错误(所有这一切都在一起):

/bin/sh: 1: ping: not found
/bin/sh: 1: ping: not found
/bin/sh: 1: ping: not found
/bin/sh: 1: ping: not found

调用上面提供的模块的脚本类似于:

def check_internet():
    if net_check.internet_on() is False:
        net_check.fire_dns_corrector()

check_internet()

0 个答案:

没有答案