Linux Debian, Mosquitto 1.3.5 및 Python 2.7.9 스크립트로 작업하고 있습니다.
터미널에서 Python 스크립트를 실행하면 (crontab에 작성한 것과 동일한 명령을 사용하여) mosquitto_pub 명령이 실행됩니다. 그러나 다음 크론을 사용하여 실행되지 않습니다.
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으로 시도했지만 명령이 시작되지 않습니다.
도움을 주셔서 미리 감사드립니다.
좋아요, 문제를 해결했습니다. mosquitto_pub의 전체 경로를 사용해야했습니다.
/usr/local/bin/mosquitto_pub
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다