mal*_*boy 2 bash gpio raspberry-pi
我有一个Raspberry Pi.我通过命令行在板上安装了WiringPi for pilot GPIO.
我做了一个名为aggiornaora.sh的脚本
gpio -g write 18 1 #it set the GPIO port to 1
#log with reverse append
(echo 'accensione';date;echo ' ') | cat - logstufa.txt > temp && mv temp logstufa.txt
Run Code Online (Sandbox Code Playgroud)
如果我试图直接执行它,这个脚本工作正常sh aggiornaora.sh.但是当cron运行脚本时,它只执行第二个操作.全部具有root权限.我通过"gpio readall"检查了这个问题.
在您看来可能是什么问题?
请注意,当您执行某些操作时crontab,它不一定会设置相同的环境变量.
最重要的环境 变量对你来说是PATH.我认为在cron你的PATH 下不包含你的gpio命令所在的目录.
你可以添加这样的行作为你的crontab的第一行:
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
Run Code Online (Sandbox Code Playgroud)
这应该可以解决您的问题,如果gpio它位于上面列出的目录之一.
调试crontab问题的典型方法是确保env.变量是你期望的变量.将这样的行添加到要调试的脚本的第一行:
set > /path/to/log/file # be sure that this file is writable
Run Code Online (Sandbox Code Playgroud)
手动运行一次,将日志文件复制到一边.然后,再次从cron运行它,比较输出 - 你会看到是什么让它们与众不同.