I’ve got a Raspberry Pi. I’ve installed on it WiringPi for pilot GPIO on the board via command line.
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
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?
Note that when you execute something from
crontab, it will not necessarily have the same environment variables set.Most important env. variable for you is
PATH. I think that undercronyour PATH does not contain directory in which yourgpiocommand is located.You can add line like this as first line of your crontab:
and this should fix your issue, if
gpiois located in one of directories listed above.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:
Run it once manually, copy logfile aside. Then, run it again from cron, compare output – you will see what makes them different.