Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When I send a reboot command(or shutdown) command to a Linux machine does it keeps that messages at somewhere and can I query it. I.e. I will send a reboot command and after that I will run another command to check will my computer at reboot(or shutdown) mode(because it will not reboot immediately it will take some time to reboot and I will check it)?

EDIT

Server sends one of that commands to client(my server and client coded at Java ) If I ping after I send i.e. shutdown command, maybe machine will shutdown but still alive(it will shutdown maybe after 2 seconds later.) If I can query my client did it received a shutdown(or reboot) command even it is still alive I will accept that OK it will shutdown(or reboot) If I can not get an answer to my query to client it means that it is not alive, so I will accept that it is shutted(or rebooting). How can I query my machine like that?

share|improve this question
    
This will probably fail at one point or another due to a race condition. You intend to query the machine, while it is in the midst of shutting down for a reboot, the services you require to connect to it could have been turned off by the time your client is making the query. Probably better to come from the other direction, and have your machine notify another machine when it is starting it's shutdown process. –  Tim Aug 2 '12 at 19:09
    
@Tim I have edited my question can you check it? –  kamaci Aug 2 '12 at 19:24
    
This might help if you use shutdown with a delay (I guess, shutdown -h +10 for ten minutes in the future): "If shutdown is called with a delay, it will create the advisory file /etc/nologin which causes programs such as login(1) to not allow new user logins. This file is created five minutes before the shutdown sequence starts." (manpage of shutdown) So, within that five minute interval, perhaps you could check if there is such a file? –  Emanuel Berg Aug 3 '12 at 2:00

1 Answer 1

up vote 2 down vote accepted

During the reboot, the runlevel is set to 6 (0 for a shutdown, 1 for maintenance mode, and 2–5 for normal operation).

if [ "$(runlevel | sed 's/.* //')" = 6 ]; then
  echo "A reboot is in progress"
fi

This is not very likely to be useful, since there will be only a very small window (often less than one second) during which the machine is still accepting commands after the reboot has been initiated.

If you need a notification after the computer has rebooted, make it send a message (over ssh, email, SNMP or whatever is convenient) as part of its startup process, after all the services you need are started.

share|improve this answer
    
How can do same thing for Free BSD? –  kamaci Aug 3 '12 at 8:07
1  
@kamaci Test the presence of /var/run/nologin, perhaps. As the name indicates, you won't be able to log in after it's there. –  Gilles Aug 3 '12 at 8:21

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.