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