我使用的是 beaglebone black,它适用于 Debian 8.6。我想在重新启动后启动一个程序。我尝试过crontab
,但没有成功。
@reboot sleep 60 && /home/debian/acspilot/start.sh
程序由 config.sh 文件和 acsp.py python 脚本组成。每个代码在终端上都可以正常工作。以下是代码:
start.sh
:
#!/bin/sh
sudo su
cd home/debian/acs/
./config_pins.sh
python acsp.py
config_pins.sh
:
#! /bin/bash
cd /sys/devices/platform/bone_capemgr
File=slots
if grep -q "Override Board Name,00A0,Override Manuf,univ-emmc" "$File";
then
cd
echo -e "\nHooray!! configuration available"
echo -e "\n UART 4 configuration p9.11 and p9.13"
sudo config-pin P9.11 uart
sudo config-pin -q P9.11
sudo config-pin P9.13 uart
sudo config-pin -q P9.13
echo -e "\n UART 1 configuration p9.26 and p9.24"
sudo config-pin P9.24 uart
sudo config-pin -q P9.24
sudo config-pin P9.26 uart
sudo config-pin -q P9.26
echo -e "\n UART 5 configuration p8.38 and p8.37"
sudo config-pin P8.38 uart
sudo config-pin -q P8.38
sudo config-pin P8.37 uart
sudo config-pin -q P8.37
echo -e "\n UART configuration end"
else
echo "Oops!!configuration is not available"
echo "Please check uEnv.txt file and only disable HDMI"
fi
acsp.py:
import Adafruit_BBIO.PWM as PWM
import Adafruit_BBIO.UART as UART
import time
# UART communication begins
UART.setup("UART1")
# pwm begins
PWM.start("P9_14", 5,50)
ser = serial.Serial(port = "/dev/ttyO1", baudrate=9600)
ser.close()
ser.open()
while ser.isOpen():
for i in range(1,99)
print i
ser.write(str(i)+"%")
PWM.set_duty_cycle("P9_14", i)
time.sleep(5)
ser.close()
UART.cleanup()
PWM.stop("P9_14")
PWM.cleanup()
答案1
该脚本有一个 sudo 行,如果它被定时到非 root 用户,则 shell 无法自行执行。相反,你应该首先成为 root
sudo su -
进而
crontab -e
作为 root 用户并添加任务行