Linux | Warning (Y/N) on shutdown command

| By Webner

Sometime unknowingly we execute shutdown or reboot command on production live server. So in order to be on the safe side we can configure the shutdown command to ask us for Y/N like explained below:

Switch to root user and then proceed

1. Add Alias in ~/.bash_profile as mentioned below:

alias shutdown='/sbin/confirm shutdown'
alias reboot='/sbin/confirm reboot'

2.. create a file at shutdown command location:

# vi /sbin/confirm<

add below content in above file:

echo "***** WARNING ***** This is Production Server $1, Please ensure do you really want to proceed!!!"
echo -n "Would you like to proceed y/n? "
read reply
if [ "$reply" = y -o "reply" = Y ]
echo "$1 cancelled"

3. Make sure the file should be executable:

chmod +x /sbin/confirm

4. Update .bash_profile using below command:

source ~/.bash_profile

Leave a Reply

Your email address will not be published. Required fields are marked *