Solved

reboot/shutdown y/n confirmation message before proceeding

Posted on 2008-09-29
7
2,348 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
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.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

707 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