18

Is it possible to re-boot my Raspberry Pi at midnight each night? I know in Linux, you'd use crontab, but I can't seem to find /etc/crontab.

  • Actually, you need to make the directory /var/spool first. I have no idea why. Try mkdir /var/spool – Elliot A. Apr 20 '17 at 23:34
27

To edit the root crontab:

sudo -i
crontab -e

put the entries you want in; there's a handy template loaded by crontab that shows you what fields are what. Once you're done and saved out of the crontab editor:

exit

to get back to the user shell.

To reboot the machine at midnight and 8 am, you need the line:

0 0,8 * * * reboot

though really, Linux doesn't need to be rebooted much, if at all.

  • 7
    Why have you spawned a separate super user shell to run crontab? Why not sudo crontab -e? – Alex Chamberlain Oct 10 '12 at 7:45
  • 2
    @AlexChamberlain - Yup, it's better not to encourage people to start a root shell unless it is absolutely necessary, but at least scruss suggested exit when you are done. – Mark Booth Oct 10 '12 at 9:40
  • @MarkBooth Completely agree. IMHO sudo should refuse to run su. There will of course be a million ways around it (including -i), but at least you will have to try harder to run a root shell. – Alex Chamberlain Oct 10 '12 at 9:43
  • I spawned a new root shell because sudo doesn't quite give you all of root's privileges and environment. I wanted to make sure that the user was really editing root's crontab. Cron is tricksy enough with its SHELL and PATH settings, so I wanted one fewer thing to go possibly wrong. – scruss Oct 10 '12 at 11:30
  • 1
    No, the new crontab is installed as soon as you exit the editor. To check, do crontab -l. But really, I'm still confused why you need to reboot so frequently. Linux doesn't need it, and unless you're testing new kernels, you can keep the system up. My home server has been up for 415 days, happily chugging along without issues. – scruss Oct 10 '12 at 13:38
5

Did you try to add an entry with

 crontab -e

Looks like you have no crontab entries and therefore the file is not created.

2

Hopefully it will help.

sudo nano /etc/crontab -e

In the file, add a line

0 0 * * * root reboot

Haven't tried but hope this helps.

  • thank you for the reply. Will this reboot the system at midnight? How will I set it for another time? So like, it reboots at midnight, then again at 8am? thanks :)! – Phorce Oct 9 '12 at 23:08
  • 2
    Don't edit the /etc/crontab directly; use the crontab commands. It's safer. – scruss Oct 9 '12 at 23:51
  • sudo crontab -e – John La Rooy Oct 10 '12 at 2:33
  • sudo nano /etc/crontab -e: The -e makes no sense, according to manpage of nano it is "Ignored, for compatibility with Pico." – macrojames Oct 10 '12 at 10:09
  • yeah thanks for clearing that up.I just started with Linux and still in the learning phase.Also from the other posts that I saw in here, it looks like its a bad idea to edit the crontab directly. – SteveIrwin Oct 10 '12 at 11:49
1

https://www.raspberrypi.org/documentation/linux/usage/cron.md

or :

use this commend:

shutdown -r hh:mm:ss 

you can add this commend to /etc/rc.local ofter reset your device run again this.

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.