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

link|improve this question

25% accept rate
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
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
2  
/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
feedback

4 Answers

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
link|improve this answer
1  
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
1  
@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
feedback

Using crontab.

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

Adding this entry to /etc/crontab should do:

0 0 * * * /sbin/shutdown -r now
link|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
feedback

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:

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

link|improve this answer
You need to echo the command to at. As it is written it will immediately reboot the computer. – Bostonvaulter Feb 22 at 1:52
feedback

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.

link|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 at 14:47
I do not think this cron line works as you think it does. – ervingsb Mar 8 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 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 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 at 19:47
show 2 more comments
feedback

Your Answer

 
or
required, but never shown

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