1

I am trying to create a cronjob, which sets the GPIO pin 10 to high at a given time. I am using the crontab of the default user "pi" and have verified, that the command

gpio -g write 10 1

works properly, executing it via the terminal / SSH connection and checking it with

gpio -g read 10

which is printing "1".

Doing the same using the crontab with

crontab -e

and writing

15 18 * * * gpio -g write 10 1

in order to get the same result like doing it manually, doesn't work and I'm getting the result "0", when I am checking with gpio -g read 10 again.

Does someone know what I'm doing wrong?

4

The most common error in crontabs seems to be not giving the full paths to programs or data used.

Use the which command to find where gpio is stored on your machine (probably /usr/local/bin/gpio) and change the command as follows

15 18 * * * /usr/local/bin/gpio -g write 10 1
0

If only cron jobs gave obvious error messages, you may be thinking!

You probably want to log output and errors when you execute something via cron. This is easily done by redirecting the standard error into the standard output. (They will merge.) In the line below I am logging both kinds of output thanks to the 2>&1

13 0 * * * /home/tai/bin/tokeep.sh > /home/tai/log/tokeep.log 2>&1

This will give you more information about what is failing and why, and probably the answer to your question will become obvious. And yes, note the use of full paths! Good luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.