Tech blog

Cronjobs - Reboot schedule

05 Feb 2024

Cronjobs - Reboot schedule

So because one of my VMs was acting up (due to a lot of transcoding on my media server) when not rebooting for a long period, I had to look for a cronjob format that would help with this issue.

I'd use cron (should already be installed):

sudo crontab -e
ShellSession

The first time you might have to choose your preferred editor (like nano)

Insert a line like -

0 4   *   *   *    /sbin/shutdown -r +5
ShellScript

at the bottom. Explanation:

m      h    dom        mon   dow       command
minute hour dayOfMonth Month dayOfWeek commandToRun
ShellScript

so the 1st line would reboot your system every day at 4:05am. (4:00am + 5 minutes)

Ctrl+X, Y, Enter should get you out of crontab (if using nano)

Note: you might have to run crontab -e as root, because shutdown needs root. crontab -e opens a file in /tmp instead of the actual crontab so that it can check your new crontab for errors. If there are no errors, then your actual crontab will be updated.

Rate this post

Comments

0 total