Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

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

-i dont know what's wrong but i cannot find the crontab..? what i have is the cron.d;cron.daily; cron.weekly; cron.monthly; I'm sorry for the noob question.Pls help me. thanks

share|improve this question
1  
The real question is why you'd want to be doing this regularly, do you have a leaky application or something? If you're scheduling regular reboots to solve a problem then you've probably got a bigger problem... –  JamesHannah Jun 27 '10 at 14:05
1  
Do you want it to reboot every night? –  Matt Simmons Jun 27 '10 at 14:33
3  
I'm not voting down, because it's sort of a policy decision (and I think nightly reboots are a bit excessive), but regularly scheduling reboots across an infrastructure are a decent way of ensuring that machines have up to date kernels and all services running are patched. I've heard a 3 month uptime limit as being a good middle ground. –  Matt Simmons Jun 27 '10 at 14:37
    
If this was a comment on the question, rather than an answer, I would upvote it. Actually I would change my mind, because the question was ambiguous about whether this was a one-time or regular thing. :) –  intuited Jun 27 '10 at 14:37
3  
/etc/crontab entry like 30 23 15-21 * 6 /sbin/shutdown -r now will reboot at 23:30 on the 3rd Saturday of every month. –  Chris S Jun 28 '10 at 17:53
show 7 more comments

4 Answers 4

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
share|improve this answer
2  
A time argument is mandatory, you can use now. –  Tobu Jun 27 '10 at 12:38
    
No ... if he want a one time command and want to type the command now, he should add the time ! –  radius Jun 27 '10 at 12:40
2  
@No, it needs a time argument such as now in the crontab line. –  Dennis Williamson Jun 27 '10 at 13:16
    
Oups yes sorry, I misread Tobu comment and think he tells 0:00 was useless in the first command... I edited to correct (and Massimo answers too) –  radius Jun 27 '10 at 13:21
add comment

Using crontab.

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

Adding this entry to /etc/crontab should do:

0 0 * * * /sbin/shutdown -r now
share|improve this answer
1  
shutdown needs a time argument such as now –  Dennis Williamson Jun 27 '10 at 13:19
1  
This will do the reboot every night. I am not sure if this is what he wants. –  cstamas Jun 27 '10 at 14:39
1  
The original question made it sound like he wanted it rebooted every night. He actually wants it rebooted every 3rd Saturday, which would still be easiest with a crontab –  Chris S Jun 28 '10 at 17:51
    
i dont know what's wrong but i cannot find the crontab..? what i have is the cron.d;cron.daily; cron.weekly; cron.monthly; I'm sorry for the noob question.Pls help me. thanks –  klauriens Jun 30 '10 at 11:00
    
It depends on the distribution you're using, but usually you should find a file called "crontab" in your system's /etc directory. You should also be able to examine the current crontab using the command "crontab -l", and to edit it using "crontab -e". –  Massimo Jun 30 '10 at 13:12
add comment

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. ;)

share|improve this answer
    
You need to echo the command to at. As it is written it will immediately reboot the computer. –  Jason Axelson Feb 22 '12 at 1:52
add comment

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.

share|improve this answer
    
the comments above of "30 23 15-21 * 6 /sbin/shutdown -r now" will work. It'll basically only run on the third week of the month, but only when it's also saturday –  Sirex Mar 6 '12 at 14:47
    
I do not think this cron line works as you think it does. –  ervingsb Mar 8 '12 at 9:36
    
I created the following two lines: "30 23 1-7 * 4 date" and "30 23 1-7 * 3 date". I got two mails last night both saying: "Wed Mar 7 23:30:02 CET 2012" –  ervingsb Mar 8 '12 at 9:37
    
the last field matches the day of the week, with zero being sunday. the 4 cronjob should not have matched on a wednesday. –  Sirex Mar 9 '12 at 15:35
    
That is what I meant. The rule you wrote do not mean what you think it means. It will trigger the job every day for a week. No matter the weekday. –  ervingsb Mar 9 '12 at 19:47
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.