Ashnook13
Posts: 120
Joined: Wed Sep 26, 2012 3:43 pm

Daily reboot not working consistently (crontab)!

Sun Feb 16, 2020 4:46 pm

I have added a line to crontab for a daily re-boot:

15 15 * * * sudo reboot

or

15 15 * * * reboot

Neither entry is consistently successful, sometimes it does but most often it does not! I just want to do a reboot every day at any time as one or more of my running PIs sometimes stops running for no apparent reason. I have used a mechanical timer in the past to turn it off and on but crontab should work.

Shouldn't it???

Cheers, Brian

bls
Posts: 538
Joined: Mon Oct 22, 2018 11:25 pm
Location: Seattle, WA
Contact: Twitter

Re: Daily reboot not working consistently (crontab)!

Sun Feb 16, 2020 4:55 pm

Which crontab file are you adding this to? There are several choices:
  • /etc/crontab - requires a username field as well
  • An entry in a file in /etc/cron.d - You would need the username field
  • crontab -e (from the user pi) - your line is correct
  • sudo crontab -e - Adds it for the root user, and you don't need the sudo
Can you be more specific as to how you created it?

Also, there should be some info in the system log. What do you see when you scroll through /var/log/syslog or /var/log/messages?

Ashnook13
Posts: 120
Joined: Wed Sep 26, 2012 3:43 pm

Re: Daily reboot not working consistently (crontab)!

Sun Feb 16, 2020 5:05 pm

I did:

sudo nano /etc/crontab

and added my stuff at the end of the file and saved it.

Which is the most reliable method?

Thanks

Ashnook13
Posts: 120
Joined: Wed Sep 26, 2012 3:43 pm

Re: Daily reboot not working consistently (crontab)!

Sun Feb 16, 2020 5:07 pm

.... and what will the line look line?

....

bls
Posts: 538
Joined: Mon Oct 22, 2018 11:25 pm
Location: Seattle, WA
Contact: Twitter

Re: Daily reboot not working consistently (crontab)!

Sun Feb 16, 2020 6:56 pm

Ashnook13 wrote:
Sun Feb 16, 2020 5:07 pm
.... and what will the line look line?

....
As I mentioned above, lines in /etc/crontab must have the username field as well, as documented in /etc/crontab:

Code: Select all

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
But, in general, it is suggested that you don't modify /etc/crontab.

You should use sudo crontab -e, which will place your crontab entry in /var/spool/cron/crontabs/root. Or, you can just use crontab -e, which will place the crontab entry in the same directory, but for the pi user. In either of these cases, you don't need the username field, but if you use the pi user's crontab you'll need the command to be sudo reboot.

Alternatively, you could create a file in /etc/cron.d and add an entry to that file with the same format as above for /etc/crontab

User avatar
jojopi
Posts: 3190
Joined: Tue Oct 11, 2011 8:38 pm

Re: Daily reboot not working consistently (crontab)!

Sun Feb 16, 2020 7:20 pm

Ashnook13 wrote:
Sun Feb 16, 2020 4:46 pm
I just want to do a reboot every day at any time as one or more of my running PIs sometimes stops running for no apparent reason.
If the Pi "stops running" somehow, then cron will likely stop too. And you said "for no apparent reason", rather than "never within 24 hours of boot", so I do not see how a daily reboot would reduce the risk of the problem occurring.

A watchdog timer is a better way to reset a Pi only when it is broken. Even better would be to diagnose the underlying issue.

Are these the same Pies you are running from a battery with solar charging?

Ashnook13
Posts: 120
Joined: Wed Sep 26, 2012 3:43 pm

Re: Daily reboot not working consistently (crontab)!

Sun Feb 16, 2020 7:52 pm

Thanks, a lot of useful information.

I don't know why a pi stops running and you are right saying if it stops running then the daily reboot won't solve anything. It is not the one running on solar as I haven't implemented it yet.

Possibly back to time switch!

Cheers

Return to “Troubleshooting”