Solved

reboot/shutdown y/n confirmation message before proceeding

Posted on 2008-09-29
7
2,104 Views
Last Modified: 2013-12-16
I am running Red Hat Linux Enterprise 3 and need to be able to display a text based customized confirmation message when either reboot or shutdown is executed with instructions before proceeding.  I am just looking to add something like "Before proceeding ensure you have gotten approval to perform this task.  Would you like to proceed y/n?"

So then they would either enter y which would proceed or n to stop the process.  Your assistance is appreciated.

In addtion can we do this to incude multiple prompts/confirmations before proceeding?

Thank you.
0
Comment
Question by:zarcow
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 450 total points
ID: 22599831
In the root .bash_profile, setup two aliase like:

alias shutdown='/usr/local/bin/confirm shutdown'
alias reboot='/usr/local/bin/confirm reboot'

With /usr/local/bin/confirm being something like:
#!/bin/bash

echo "Before proceeding to perform $1, please ensure you have approval to perform this task"

echo -n "Would you like to proceed y/n? "

read reply
 

if [ "$reply" = y -o "$reply" = Y ]

then

   /sbin/$1

else

   echo "$1 cancelled"

fi

Open in new window

0
 

Author Comment

by:zarcow
ID: 22600068
Thank you for the quick response.  This looks like what I am looking for.  Just a quick clarification, how would the script look if I needed multiple prompts/confirmations?  So after the first y choice it prompts for another one before actually proceeding to execute the reboot/shutdown command.
0
 
LVL 19

Assisted Solution

by:jools
jools earned 50 total points
ID: 22600286
You could nest a few more if's

I've just really cannibalised TinTin's script here as an attempt at humor... :-)

#!/bin/bash
echo "Before proceeding to perform $1, please ensure you have approval to perform this task"
echo -n "Would you like to proceed y/n? "
read reply
 
if [ "$reply" = y -o "$reply" = Y ]
then
   echo "Really really???"
   read reply2
   if [ "$reply2" = y -o "$reply2" = Y ]
   then
      echo "Really really with sugar on top???"
      read reply3
      if [ "$reply3" = y -o "$reply3" = Y ]
      then
         /sbin/$1
      fi
   fi
else
   echo "$1 cancelled"
fi
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 48

Accepted Solution

by:
Tintin earned 450 total points
ID: 22600687
A function can make multiple prompts easier
#!/bin/bash

prompt()

{

  while true

  do

    echo -n "$* y/n? "

    read reply

    if [ "$reply" = y -o "$reply" = Y ]

    then

       return 0

    elif [ "$reply" = n -o "$reply" = N ]

    then

       echo "Action cancelled"

       exit 1

    else

       echo "Please enter 'y' or 'n'"

    fi

  done

}
 

echo "Before proceeding to perform $1, please ensure you have approval to perform this task"

if prompt "Would you like to proceed"

then

   prompt "Are you absolutely sure" && /sbin/$1

fi

Open in new window

0
 
LVL 14

Expert Comment

by:sjm_ee
ID: 22601343
Nice one jools
0
 

Author Closing Comment

by:zarcow
ID: 31501316
Thank you very much for your assistance.
0
 
LVL 19

Expert Comment

by:jools
ID: 22604137
:-)

Sorry Tintin I kinda stole your thunder.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now