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.

Assuming you've just entered the command shutdown -h now (or something equivalent), is there realistically anything you can do (if you're quick enough) to prevent the machine shutting down?

share|improve this question
    
Once you invoke shutdown -h now, I believe you lose command line access immediately similarly to halt -p so there isn't much you can do. –  Ken Jan 18 '11 at 16:41
    
@Ken: on Ubuntu and Centos connected via putty the command line remains available for a few seconds. –  Iain Jan 18 '11 at 18:43
    
Why say "now" if you don't mean "right now"? –  Fred Nurk Jan 18 '11 at 20:27

3 Answers 3

suppose, you sent a reboot or shutdown message to all terminal for maintenance purpose that the "server is going to reboot or shutdown for maintenance purpose within 10 minutes"

This kind of command can cancel.

just press Ctrl+C

share|improve this answer

If you are fast enough you can issue an init 2 (or whatever runlevel you want) and that will likely stop the shutdown. Anything involving killing the shutdown command will fail as the command runs too quickly

I tried this with the script below and and even it's not fast enough to stop the shutdown

#!/bin/bash
shutdown -h now
shutdown -c "Aborting Shutdown"

Broadcast message from iain@iain-ubuntu
        (/dev/pts/0) at 16:50 ...

The system is going down for halt NOW!
shutdown: Cannot find pid of running shutdown

Where as interactively

shutdown -h now
init 2 

the system stays up.

share|improve this answer

You can run shutdown -c to cancel an already running shutdown.

share|improve this answer
1  
Did not believe it at first, but yes. More specifically ctrl+c –  Ken Jan 18 '11 at 16:45
2  
@Ken: shutdown -c and [Ctrl]+[c] are entirely different. shutdown -c is a command which cancels a previously scheduled shutdown (even "now" is scheduled in this sense --- but whether the cancellation will prevent the reboot is a bit of a race in that case). [Ctrl]+[c] will cause you terminal to generate a SIGINT (interrupt signal) to whichever process was currently attached to it. This might work on a running shutdown command but that's rather incidental to your question. –  Jim Dennis Jan 18 '11 at 17:25
1  
@Jim Dennis: I'm aware of the difference between ctrc+c and shutdown -c. But given the speed of the -now option rather than its scheduled sibling, ctrl+c would be the fastest route to that end. I didn't believe you could stop an immanent shutdown, even more surprised that you can interrupt it, but apparently you can, but it's a race as you stated. –  Ken Jan 18 '11 at 17:45

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.