LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 04-20-2010, 11:32 AM   #1
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,525

Rep: Reputation: 37
Better to use "at" command instead of time variable in shutdown?


OK, I was reading that if I want to do a one time scheduled command, I should use at, which I've never done, as opposed to cron, which i'm kinda familiar with. But what I want to do is reboot my server at 3am tomorrow and force it to check the file systems with a shutdown -rF.

For this do I even need to use "at" or could I just say shutdown -rF 3:00

Will that also know that I mean 3am tomorrow and not say in 3 minutes from now or 3pm?

I never done this before so I'm kinda paranoid, just looking for some confirmations from the experts so I don't really screw something up. thanks in advance.
 
Old 04-20-2010, 11:51 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,502

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Indeed it is not specified in the man page, but hour is in 24h format. Confirmation from the source code:
Code:
  /* Time in hh:mm format. */
  if (sscanf(when, "%d:%2d", &hours, &mins) != 2) usage();
  if (hours > 23 || mins > 59) usage();
  time(&t);
  lt = localtime(&t);
  wt = (60*hours + mins) - (60*lt->tm_hour + lt->tm_min);
  if (wt < 0) wt += 1440;
where you can see that maximum accepted value for hours is 23. And yes, you don't really need to schedule job through at, since shutdown has its own time manager.

Last edited by colucix; 04-20-2010 at 11:52 AM.
 
Old 04-20-2010, 11:53 AM   #3
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Squeeze
Posts: 5,770

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
This is from the shutdown man page:
Quote:
The time argument can have different formats. First, it can be an absolute time in the
format hh:mm, in which hh is the hour (1 or 2 digits) and mm is the minute of the hour
(in two digits). Second, it can be in the format +m, in which m is the number of minutes
to wait. The word now is an alias for +0.

If shutdown is called with a delay, it creates the advisory file /etc/nologin which
causes programs such as login(1) to not allow new user logins. Shutdown removes this file
if it is stopped before it can signal init (i.e. it is cancelled or something goes
wrong). It also removes it before calling init to change the runlevel.
As you can see, using shutdown without at may cause problems if users try to login. So, if I were in your place, I would schedule the shutdown/reboot with at.
 
Old 04-20-2010, 11:53 AM   #4
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,525

Original Poster
Rep: Reputation: 37
Thanks for confirming colucix. I didn't see it in the man page either so wanted to ask.

so guess me doing a

shutdown -rF 3:00

will indeed restart and force a disk check on all partitions at 3am tomorrow.
 
Old 04-20-2010, 11:54 AM   #5
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,525

Original Poster
Rep: Reputation: 37
Quote:
Originally Posted by bigrigdriver View Post
This is from the shutdown man page:

As you can see, using shutdown without at may cause problems if users try to login. So, if I were in your place, I would schedule the shutdown/reboot with at.
OH, so if I don't use at, I wont be able to SSH back into the server until after it restarts?? that would be BAD, just want to make sure i'm understanding right.
 
Old 04-20-2010, 11:56 AM   #6
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,525

Original Poster
Rep: Reputation: 37
my other problem is I don't know how to use at, could someone help me?
 
Old 04-20-2010, 12:00 PM   #7
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Squeeze
Posts: 5,770

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
It's there in the man page in black and white. So, use the shutdown command without at at your own risk. If it does cause problems with user logins, you can always kill the pending shutdown, which put you back at square one: do I or don't I schedule shutdown with or without at.

I can't think of anything else to say about it.

For examples using at: http://www.kombitz.com/2009/09/17/li...d-at-examples/

www.google.com/linux is your friend. Use it to search for answers to questions you have about GNU/Linux.

Last edited by bigrigdriver; 04-20-2010 at 12:07 PM.
 
Old 04-20-2010, 12:12 PM   #8
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,502

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Well.. the man page also does not mention that /etc/nologin is created 5 minutes before shutdown. Again the source code comes in handy:
Code:
  if (wt <= 5 && !didnolog) {
          donologin(wt);
          didnolog++;
  }
where wt is the waiting time in minutes.
 
Old 04-20-2010, 12:19 PM   #9
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,525

Original Poster
Rep: Reputation: 37
OK, so as long as I just do a shutdown -rF 3:00, it will allow new SSH sessions up until 5 minutes before the reboot. That's a pretty nifty little feature they have hidden in there, I never would have know about it.

I'm using RHEL, would it vary between distros or is there something I should check on my server?

Thanks for all the help colucix, I'm learning a lot here.
 
Old 04-20-2010, 12:21 PM   #10
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,502

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Quote:
Originally Posted by rjo98 View Post
I'm using RHEL, would it vary between distros or is there something I should check on my server?
I think it's the same for all distros, but I cannot tell it for sure. Which package provides the shutdown command on your system?
 
Old 04-20-2010, 12:23 PM   #11
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,525

Original Poster
Rep: Reputation: 37
I'm sorry, but I dont know how to check that to tell you.
 
Old 04-20-2010, 12:38 PM   #12
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,502

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Code:
rpm -qf /sbin/shutdown
the -f option tells which package provides the specified file. In any case I just checked the RHEL sources (actually CentOS) and it is provided by SysVinit (actually I think the shutdown command is provided only by this package, I'd just like to check the version). For sure the behaviour is the same since RHEL4.
 
Old 04-20-2010, 12:41 PM   #13
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,525

Original Poster
Rep: Reputation: 37
Here's what mine said when i issued the command you said.

SysVinit-2.85-4.4
 
Old 04-20-2010, 12:49 PM   #14
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,502

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Ok. I confirm the /etc/nologin appears 5 minutes before shutdown time!
 
Old 04-20-2010, 12:54 PM   #15
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,525

Original Poster
Rep: Reputation: 37
Great. Thanks colucix. Now I just have to figure out how if when it goes to shutdown if it has a kernel panic, how to get it to skip over it and continue the reboot and forced disk check. that way the server isn't sitting there doing nothing for hours before i get in.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
a simple bash command causing "bad variable name" johnhelen Linux - Newbie 7 02-20-2010 01:21 AM
Sometimes "shutdown" command takes a lot of time vhn Linux - Embedded & Single-board computer 2 11-17-2009 10:20 PM
How to get the "data type" of an "unknown variable" in "C Language" ? Affair Programming 8 06-20-2009 12:30 PM
Shell Variable available within Samba "print command" thibert Linux - Networking 0 12-12-2005 01:02 PM
Bash Script: Problem running variable command containing "" Paasan Programming 2 01-21-2004 01:45 AM


All times are GMT -5. The time now is 05:20 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration