Solved

reboot/shutdown y/n confirmation message before proceeding

Posted on 2008-09-29
7
2,151 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
1. Introduction As many people are interested in Linux but not as many are interested or knowledgeable (enough) to install Linux on their system, here is a safe way to try out Linux on your existing (Windows) system. The idea is that you insta…
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.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

929 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

11 Experts available now in Live!

Get 1:1 Help Now