Crontab is the Linux and MacOS version of Windows Task Scheduler. It is where the computer looks to tell it if it has any tasks which need to be completed.
We often use it to perform routine maintenance tasks which, once tested and working correctly, are better left for the computer to do by itself.
A good example is a weekly reboot of the computer
You can schedule a weekly restart by adding a cron job that runs a reboot command at your desired time. For example, to restart your computer every Sunday at 3:00 AM, you could add the following line to your root crontab:
0 3 * * 0 /sbin/shutdown -r now
• 0 – The minute (0th minute)
• 3 – The hour (3 AM)
• * – Every day of the month
• * – Every month
• 0 – The day of the week (0 or 7 typically represents Sunday)
Since restarting the computer requires administrative privileges, you should edit the root crontab:
sudo crontab -e
Insert the line above into the file and save it.
3. Verify the Cron Job:
You can list your root cron jobs with:
sudo crontab -l
On some systems, you might prefer to use the reboot command directly:
0 3 * * 0 /sbin/reboot
Ensure that all important work is saved before the scheduled restart, as any unsaved data will be lost.
The paths (/sbin/shutdown or /sbin/reboot) may vary depending on your system. You can verify the correct path using the which shutdown or which reboot commands.
Cron uses the system time zone. Make sure your system time is set correctly so that the restart happens when you expect it to.
By following these steps, your computer will automatically restart once a week at the scheduled time.