0

I have a Raspberry Pi 2, which I use as kiosk, for that I have installed Raspbian based FullPageOS distro.

Everything works fine, except some commands fail silently when trying to run from crontab.

I have 2 commands for switching kiosk on and off at certain times by the pi user:

$crontab -l -u pi
# m h  dom mon dow   command
05 9 mon-fri * * /bin/bash /home/pi/scripts/dispon.sh >> /tmp/cronjob.log 2>&1
15 18 mon-fri * * /usr/bin/xset -display :0 dpms force off >> /tmp/cronjob.log 2>&1
*/3 * * * * /usr/bin/touch /tmp/1111 >> /tmp/cronjob.log 2>&1

As you can see, I have tried it different ways: to execute xset directly in the monitor off sequence, and as part of script, when executing the monitor on.

Contents of the dispon.sh script (it is chmod a+x):

#!/bin/bash
xset -display :0 dpms force on
xset -display :0 -dpms

Neither of commands appear to work (display doesn't turn on/off) and neither leaves any error message in /tmp/cronjob.log

The touch command does work and touch the file though.

Both xset and dispon.sh work fine when run by pi user from SSH connection.

Any ideas??

  • The cron/crontab don't known $PATH so you should use absolute path for used binaries. – mariaczi Jun 19 '18 at 9:41
  • @mariaczi yes it does, it's just that by default it's reduced to /usr/bin:/bin. – roaima Jun 19 '18 at 10:03
4

The man page for the crontab file format (man 5 crontab) writes,

Names can also be used for the "month" and "day of week" fields. Use the first three letters of the particular day or month (case doesn't matter). Ranges or lists of names are not allowed.

Notice the last sentence: you cannot use mon-fri (but you can use 1-5).

You have also missed that the comment (first line) reminds you of the correct field order: minute, hour, day-of-month, month, day-of-week, command; but you had placed the day-of-week values too soon. This corrected crontab file should work better for you:

SHELL=/bin/bash
PATH=/usr/bin:/bin:/usr/local/bin:/home/pi/scripts

# m h  dom mon dow   command
05 9 * * 1-5     dispon.sh >> /tmp/cronjob.log 2>&1
15 18 * * 1-5    xset -display :0 dpms force off >> /tmp/cronjob.log 2>&1
*/3 * * * *      touch /tmp/1111 >> /tmp/cronjob.log 2>&1

Finally, if you find that cron is apparently ignoring your entries, you can search for its recent log reports to see what (if anything) is going on:

grep CRON /var/log/syslog
  • Thanks, I was getting very puzzled by what turned out to be a clumsy mistake! Btw, it seems that at least on recent Ubuntus, you can use names of weekdays instead of numbers for ranges. I have sevaral cron entries on another server, where the ranges run ok with mon-fri (but in the correct places there, of course). – Gnudiff Jun 19 '18 at 13:11
  • @Gnudiff we're not on Ubuntu here - you tagged the question raspbian. – roaima Jun 19 '18 at 14:59
  • yes, I understand. I didn't realizē crons differed as much between Debian/Ubuntu and Raspberry. – Gnudiff Jun 19 '18 at 19:45
  • @Gnudiff Debian also claims no ranges of names. It must be an Ubuntu thing. – roaima Jun 19 '18 at 20:06
1

Your dom field column 3 should specify the days that this command should run each month, eg 1-3 to run only days 1 to 3 each month. You need to move the week days mon-fri to the last column.

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.