覆盆子的GPIO命令无法通过crontab工作 [英] GPIO command for raspberry not working via crontab

查看:63
本文介绍了覆盆子的GPIO命令无法通过crontab工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Raspberry Pi.我已经通过命令行在板上安装了WiringPi上的引航GPIO.

I've got a Raspberry Pi. I've installed on it WiringPi for pilot GPIO on the board via command line.

我已经完成了一个名为aggiornaora.sh的脚本

I've done a script called 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

如果我尝试直接通过 sh aggiornaora.sh 执行该脚本,则该脚本可以正常工作.但是,当cron运行脚本时,它仅执行第二个操作.全部具有root权限.我已经通过"gpio readall"检查了此问题.

This script work fine if I try to exec it directly via sh aggiornaora.sh. But when cron run the script, it do only the second action. All with root permission. I've checked this problem through "gpio readall".

您认为可能是什么问题?

In your opinion what could be the problem?

推荐答案

请注意,当您从 crontab 执行某些操作时,不一定会设置相同的环境变量.

Note that when you execute something from crontab, it will not necessarily have the same environment variables set.

最重要的环境您的变量是 PATH .我认为在 cron 下,您的PATH不包含 gpio 命令所在的目录.

Most important env. variable for you is PATH. I think that under cron your PATH does not contain directory in which your gpio command is located.

您可以将以下行添加为crontab的第一行:

You can add line like this as first line of your crontab:

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin

,如果 gpio 位于上面列出的目录之一中,这应该可以解决您的问题.

and this should fix your issue, if gpio is located in one of directories listed above.

调试crontab问题的典型方法是确保环境.变量就是您所期望的.将这样的行添加到脚本的第一行进行调试:

Typical way to debug crontab issues is to make sure that env. variables are what you expect them to be. Add line like this into first line of the script to debug:

set > /path/to/log/file    # be sure that this file is writable

手动运行一次,将日志文件放在一边.然后,从cron再次运行它,比较输出-您将看到使它们与众不同的原因.

Run it once manually, copy logfile aside. Then, run it again from cron, compare output - you will see what makes them different.

这篇关于覆盆子的GPIO命令无法通过crontab工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆