Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Ok I admit it...

I stupidly shutdown my remote server via ssh instead of restarting it like I wanted to do :(

To prevent me doing a silly again, is there a way to display a warning / confirmation on a shutdown command? (like "Are you sure you want to shut down this server?" yes/no )

OR, can I not allow shutting down (but not restarting because I still might need to do that from time to time) over ssh?

share|improve this question
    
Are you also going to disable halt, telinit and other methods to shutdown? –  Zoredache Jun 3 '10 at 5:22
    
Well no. I just want to idiot proof it from myself. ;) –  Ganesh Shankar Jun 3 '10 at 5:46

4 Answers 4

up vote 5 down vote accepted

Try molly-guard:

protects machines from accidental shutdowns/reboots
share|improve this answer
    
how good: One of the scripts checks for existing SSH sessions. If any of the four commands are called interactively over an SSH session, the shell script prompts you to enter the name of the host you wish to shut down. This should adequately prevent you from accidental shutdowns and reboots. –  Grizly Jun 3 '10 at 8:07
    
Awesome! That exactly the kind of thing I was looking for... :) –  Ganesh Shankar Jun 4 '10 at 3:48

you could alias the shutdown command from your account, edit

/home/username/.bashrc

add

function savemefromlookingstupid(){
    echo 'Are you sure you wanna SHUTDOWN? [n]'
    read yesno
    if [ $yesno == y ]; then
        sudo /usr/sbin/shutdown -h now
        exit 1
    fi
    echo 'Thought so.. watch it, that was close..'
}
alias restart_server='sudo /user/sbin/shutdown -r now'
alias shutdown='savemefromlookingstupid'

To restart, you would run "restart_server"

share|improve this answer
1  
Not sure there it is wise to set up an alias. What happens when you are on some other system that doesn't have the alias? I think it is better to simply learn to be cautious about what commands you issue while logged in as root. There are tons of other things you can do to make a mess of things. –  Zoredache Jun 3 '10 at 5:24
    
@Zoredache you do make a good point. I now have to head into the remote location today to press a switch... so you can consider my lesson learnt! (I think I still will create the alias though) –  Ganesh Shankar Jun 3 '10 at 5:48
    
well, its ubuntu, so no root.. but I see your point. If you really wanted to save yourself, you would rename the binary itself.. I went the less invasive route. The question was about getting a warning though, and I got to play with scripting.. which I like ;-) –  Grizly Jun 3 '10 at 6:03

You can make a rule always pass time argument to shutdown:

# shutdown -h +2

Then you can cancel shutdown within 2 minutes:

# shutdown -c
share|improve this answer

No need to set up an alias. The "reboot" command is fairly standard on linux. Stop using the shutdown command... use reboot.

share|improve this answer

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.