我已将cronie(https://github.com/cronie-crond/cronie)构建为yocto图像,并带有以下/etc/crontab
:
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
# 1 * * * * root cd / && run-parts /etc/cron.hourly
# 30 7 * * * root cd / && run-parts /etc/cron.daily
# 42 7 * * 7 root cd / && run-parts /etc/cron.weekly
# 55 7 1 * * root cd / && run-parts /etc/cron.monthly
*/2 * * * * foo /usr/bin/python3 /home/foo/code/heartbeat.py && /usr/bin/python3 /home/foo/code/amplitude.py
心跳有效,但幅度无效。振幅涉及python调用子进程:
import subprocess
import numpy
import wavio
from base_reading import publishReading
try:
subprocess.run(['/usr/bin/arecord', '-D', 'plughw:0', '-c1', '-r', '48000', '-f', 'S32_LE', '-t', 'wav', '-d', '10', '-V', 'mono', '-v', '/tmp/file.wav'])
except:
subprocess.run(['/usr/bin/arecord', '-D', 'plughw:1', '-c1', '-r', '48000', '-f', 'S32_LE', '-t', 'wav', '-d', '10', '-V', 'mono', '-v', '/tmp/file.wav'])
source = "/tmp/file.wav"
file = wavio.read(source).data
amplitude = numpy.mean(file)
stddev = numpy.std(file)
subprocess.run(['rm', '/tmp/file.wav'])
publishReading({'sensor_type': 'noise', 'mean': amplitude, 'stddev': stddev})
我已经在Google上进行了很多搜索,总的结论似乎是对我拥有的所有内容都使用绝对路径,但这仍然行不通。 FWIW,即使使用python的相对路径,心跳(无子进程)也可以完美工作。
奇怪的是,日志文件似乎不存在,这很可能是yocto的事情(我认为它是基于busybox的)。