LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Better to use "at" command instead of time variable in shutdown? (https://www.linuxquestions.org/questions/linux-newbie-8/better-to-use-at-command-instead-of-time-variable-in-shutdown-803083/)

anon091 04-20-2010 11:32 AM

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.

colucix 04-20-2010 11:51 AM

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.

bigrigdriver 04-20-2010 11:53 AM

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.

anon091 04-20-2010 11:53 AM

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.

anon091 04-20-2010 11:54 AM

Quote:

Originally Posted by bigrigdriver (Post 3941600)
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.

anon091 04-20-2010 11:56 AM

my other problem is I don't know how to use at, could someone help me?

bigrigdriver 04-20-2010 12:00 PM

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.

colucix 04-20-2010 12:12 PM

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.

anon091 04-20-2010 12:19 PM

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.

colucix 04-20-2010 12:21 PM

Quote:

Originally Posted by rjo98 (Post 3941621)
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?

anon091 04-20-2010 12:23 PM

I'm sorry, but I dont know how to check that to tell you.

colucix 04-20-2010 12:38 PM

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.

anon091 04-20-2010 12:41 PM

Here's what mine said when i issued the command you said.

SysVinit-2.85-4.4

colucix 04-20-2010 12:49 PM

Ok. I confirm the /etc/nologin appears 5 minutes before shutdown time! :)

anon091 04-20-2010 12:54 PM

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.


All times are GMT -5. The time now is 09:02 PM.