Ubuntu – How to configure Ubuntu to reboot every day at a given time


Using the terminal or a bash file, how can I configure Ubuntu to reboot every day at (say for instance) 3 AM?

In other words, I want to schedule an automatic reboot through the terminal.

I haven't been able to find anything related to this on Google or AskUbuntu, and I'm fairly new to Ubuntu in general (just got my new Raspberry Pi).

Best Answer

Edit the crontab entries using crontab -e command (by default this will edit the current logged-in users crontab) and add the following line:

0 3 * * * echo $PASSWD | sudo -S reboot
#change $PASSWD with your password

Save the file and check the new crontab entry with crontab -l.

If you want to use only:

0 3 * * * sudo reboot

as crontab, this doesn't work normally and you should check this post to see how can you make it to work.

Or, simple add the crontab to the root user's crontab file offering the complete path for the reboot command using sudo crontab -e:

0 3 * * * /sbin/reboot
Related Question