Solved

reboot/shutdown y/n confirmation message before proceeding

Posted on 2008-09-29
7
2,206 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AWS- KeepAlived notify script not working 23 83
VMware Workstation 12 Player 16 75
SonarQube on Linux vs Windows 3 28
Securing Azure Oracle instance of Linux VM 4 58
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
This article will explain how to establish a SSH connection to Ubuntu through the firewall and using a different port other then 22. I have set up a Ubuntu virtual machine in Virtualbox and I am running a Windows 7 workstation. From the Ubuntu vi…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

778 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