Python DietPi—手动运行脚本可以工作—但从postboot.d开始会抛出I/O错误

Python DietPi—手动运行脚本可以工作—但从postboot.d开始会抛出I/O错误,python,raspberry-pi,privileges,Python,Raspberry Pi,Privileges,我试图在用DietPi启动Raspberry时自动运行脚本。 我的脚本启动一个Python3程序,然后在最后启动一个外部程序MP4Box,该程序将2个视频文件合并到lighttp Web服务器文件夹中的一个mp4中 当我手动启动脚本时,一切正常。但是当脚本在引导时自动启动时,当涉及到外部程序MP4Box时,我得到一个错误: Cannot open destination file /var/www/Videos/20201222_151210.mp4: I/O Error 启动pythons的

我试图在用DietPi启动Raspberry时自动运行脚本。 我的脚本启动一个Python3程序,然后在最后启动一个外部程序MP4Box,该程序将2个视频文件合并到lighttp Web服务器文件夹中的一个mp4中

当我手动启动脚本时,一切正常。但是当脚本在引导时自动启动时,当涉及到外部程序MP4Box时,我得到一个错误:

Cannot open destination file /var/www/Videos/20201222_151210.mp4: I/O Error
启动pythons的脚本是“startcam”——它位于/var/lib/dietpi/postboot.d文件夹中

#!/bin/sh -e
# Autostart RaspiCam
cd /home/dietpi
rm -f trigger/*
python3 -u record_v0.1.py > record.log 2>&1 &
python3 -u motioninterrupt.py > motion.log 2>&1 &
postboot.d中的readme.txt说:

# /var/lib/dietpi/postboot.d is implemented by DietPi and allows to run scripts at the end of the boot process:
# - /etc/systemd/system/dietpi-postboot.service => /boot/dietpi/postboot => /var/lib/dietpi/postboot.d/*
# There are nearly no restrictions about file names and permissions:
# - All files (besides this "readme.txt" and dot files ".filename") are executed as root user.
# - Execute permissions are automatically added.
# NB: This delays the login prompt by the time the script takes, hence it must not be used for long-term processes, but only for oneshot tasks.
因此,它还应该以根权限开始我的脚本。这就是抛出错误的脚本“record_v0.1.py”的(部分):

import os
os.system('MP4Box -fps 15 -cat /home/dietpi/b-file001.h264 -cat /home/dietpi/a-file001.h264 -new /var/www/Videos/file001.mp4 -tmp ~ -quiet')
当我手动启动python程序(以root用户身份登录)时:

一切正常,我得到的信息不是错误:

Appending file /home/dietpi/Videos/b-20201222_153124.h264
No suitable destination track found - creating new one (type vide)
Appending file /home/dietpi/Videos/a-20201222_153124.h264
Saving /var/www/Videos/20201222_153124.mp4: 0.500 secs Interleaving

感谢您的每一个提示

与描述相反,postboot.d中的脚本不会作为root执行。因此,我将脚本更改为:

#!/bin/sh -e
# Autostart RaspiCam
cd /home/dietpi
rm -f trigger/*
sudo python3 -u record_v0.1.py > record.log 2>&1 &
sudo python3 -u motioninterrupt.py > motion.log 2>&1 &
现在,它们以root用户身份运行,一切都可以正常工作

#!/bin/sh -e
# Autostart RaspiCam
cd /home/dietpi
rm -f trigger/*
sudo python3 -u record_v0.1.py > record.log 2>&1 &
sudo python3 -u motioninterrupt.py > motion.log 2>&1 &