0

我正在使用 Linux Debian、Mosquitto 1.3.5 和 Python 2.7.9 脚本。

如果我在终端中运行 Python 脚本(使用我在 crontab 中编写的相同命令),mosquitto_pub 命令将运行。但它不使用以下 cron 执行:

2,12,22,32,42,52 * * * * /usr/bin/python /home/user/ma.py

cron 将启动脚本并执行脚本的第一部分(将一些数据写入 csv 文件),但不会执行 mosquitto_pub 命令。

我的 Python 脚本的一部分:

liv = str(190 + float(parser.data[157]))
    try:
        ssl = '/home/user/file.pem'
        base = "mosquitto_pub -h host -p 8883 -t measures -q 2 --cafile " + ssl
        epoch = datetime.utcfromtimestamp(0)
        delta = datetime.strptime(dttime, "%Y-%m-%dT%H:%M:%SZ") - epoch
        ds = delta.total_seconds()
        mqttStr = base + " -m 'FILE_LL," + str(int(ds)) + ',' + liv + "'"
        subprocess.Popen(mqttStr, shell=True)
    except:
        print "It was not possible to send your data via mqtt.", sys.exc_info()[0], datetime.utcnow()

我尝试了 os.system、subprocess.call 和 subprocess.Popen,但命令没有启动。

提前感谢您的帮助。

4

1 回答 1

1

好的,我解决了这个问题。我必须使用 mosquitto_pub 的完整路径:

/usr/local/bin/mosquitto_pub
于 2015-04-15T09:45:30.500 回答