【问题标题】:mosquitto_pub command in python code not executing in crontabpython代码中的mosquitto_pub命令未在crontab中执行
【发布时间】:2015-04-03 10:14:03
【问题描述】:

我正在使用 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,但命令没有启动。

提前感谢您的帮助。

【问题讨论】:

  • 文档页面缺少 Ubuntu 的一步:sudo apt-get install mosquitto-clients 使用 mosquitto_pubmosquitto_sub

标签: python-2.7 mosquitto


【解决方案1】:

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

/usr/local/bin/mosquitto_pub

【讨论】:

    猜你喜欢
    • 2017-04-21
    • 1970-01-01
    • 2019-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-28
    • 2019-09-11
    相关资源
    最近更新 更多