Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

reboot/shutdown y/n confirmation message before proceeding

Posted on 2008-09-29
7
Medium Priority
?
2,560 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 1800 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 200 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
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
LVL 48

Accepted Solution

by:
Tintin earned 1800 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

Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses

604 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