55

I'm new in Linux and I want to schedule a reboot at midnight. How should I do it?

Edits:

  • I'm sorry I didn't put the complete details. I want a reboot every 3rd Saturday of the month at 23:30.

  • I don't know what's wrong but I cannot find crontab. What I have is cron.d; cron.daily; cron.weekly; cron.monthly;

I'm sorry for the noob question. Pls help me. Thanks.

Chris W.
  • 103
klauriens
  • 571

6 Answers6

71

Type shutdown -r 0:00 and it will reboot at midnight.

If you want to reboot each night, add a cron entry using crontab -e as root to run shutdown -r each midnight

@midnight shutdown -r now
Eric Fossum
  • 225
  • 3
  • 11
radius
  • 9,701
18

Another option is the at command, available on many Linux distributions. See the man page for more info, but the general syntax for your purpose would be:

echo "reboot" | at 0000 jun 27

To quote the OS X man page:

at - executes commands at a specified time

Sound like what we're talking about. ;)

sorin
  • 8,454
17

Using crontab.

http://en.wikipedia.org/wiki/Crontab

Adding this entry to /etc/crontab should do:

0 0 * * * /sbin/shutdown -r now
radius
  • 9,701
Massimo
  • 72,827
2

As far as I know, you cannot use cron to schedule tasks for "last Friday of each month" or "third Thursday in each month". What you can do, however ugly it seems, is to have a script run every Saturday at 23:30 and then have this script determine if this particular Saturday is the third Saturday of the week (can be done using date and maybe cal commands).

I hope this helps. I have not found an elagant solution to this problem. I found this thread, because I was searching for a solution for the same problem.

ervingsb
  • 385
1

1) at the command line type which reboot
2) once you know where reboot is located (usually /sbin/reboot) cd into one of the the directories in /etc/cron.daily , /etc/cron.weekly , /etc/cron.hourly etc... ie cd /etc/cron.weekly

3) create a file (using nano or vim) call it zzreboot and add the following lines:

#!/bin/sh
/sbin/reboot

The reason you want to call the file zzwhatever is to make sure it's the last job called after all other jobs. To make sure just do an ls -l in the directory and verify it's the last file.

0

I know this is an old question, still I would like to answer it. On your terminal logged in as root follow below steps:

  1. #crontab -e this would open the cron file to write your cron jobs
  2. add a new line like30 23 15-21 * sat /path/to/reboot. This cron job would reboot the system every 3rd sat of the month at 11.30 pm.
  3. save and exit