0

@reboot commands are not being run from cron. I verified this with

grep cron /var/log/syslog

which showed

Jul 25 16:17:01 picam2 /USR/SBIN/CRON[4487]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Jul 25 17:17:01 picam2 /USR/SBIN/CRON[4497]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Jul 25 18:17:01 picam2 /USR/SBIN/CRON[4507]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Jul 25 19:17:01 picam2 /USR/SBIN/CRON[4623]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Jul 25 19:35:21 picam2 crontab[4714]: (root) BEGIN EDIT (root)
Jul 25 19:36:03 picam2 crontab[4714]: (root) REPLACE (root)
Jul 25 19:36:03 picam2 crontab[4714]: (root) END EDIT (root)
Jul 25 19:58:06 picam2 crontab[4752]: (root) LIST (root)

cron is running

ps aux | grep cron

also setup cron logging by uncommenting the entry in /etc/rsyslog.conf but no /var/log/cron.log is created on the next boot.

From what I can see there should have been a

(CRON) INFO (Running @reboot jobs)

entry followed by

CMD my command

I found the /var/run/crond.reboot file was created 3 days ago even though I had rebooted a number of times. After deleting it and rebooting it has not come back. I thought this was the mechanism cron used to avoid rerunning @reboot jobs?

The crontab was created with sudo and

sudo crontab -u root -l

returns

@reboot echo "hi" > /home/pi/reboot.txt 2>&1
@reboot /home/pi/launcher.sh >>/home/pi/logs/cron.log 2>&1

although it's not directly important, neither the /home/pi/reboot.txt nor the /home/pi/logs/cron.log get created on boot. Both commands work fine when run from a sudo -s shell

New Raspian install (2015/05/05 image) with apt-get update and apt-get upgrade

Linux picam2 3.18.11+ #781 PREEMPT Tue Apr 21 18:02:18 BST 2015 armv6l GNU/Linux

"man cron" shows this the standard Vixie Cron which does support @reboot

8
  • That's strange. I inserted first line and it works for me. It creates reboot.txt with hi in it. Jul 26, 2015 at 6:36
  • do you have the /var/run/crond.reboot file dated from when you booted the Pi?
    – rob
    Jul 26, 2015 at 9:20
  • Yes. I do have it. Jul 26, 2015 at 9:23
  • The only weird thing I can think of that might relate to all this was I ran rpi-update -y when I first setup the Pi and it failed. I had had the exact problem with another Pi a few weeks earlier so I just set the date via ntp and it still failed(even though that had been the fix). and that when ever I delete anything as the pi user it tells me its write protected but lets me delete anyway. Yes, I am clutching at straws now.
    – rob
    Jul 26, 2015 at 9:23
  • do you had a the INFO (running @reboot jobs) line when running grep cron /var/log/syslog ?
    – rob
    Jul 26, 2015 at 9:24

1 Answer 1

3

I found the answer and it is so ridiculously simple its scary.

I had been running the same command over and over each time I wanted to reboot, using the shell history.

sudo shutdow -r now;exit

which exited ssh and I thought rebooted the Pi, but no, it was sitting there waiting for me to ssh back in. It should be

sudo shutdown -r now;exit

It works fine now the Pi actually rebooted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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