How to shutdown Linux box with user confirmation?

Hi Guru's
Am looking for linux reboot command which get executed after user confirmation .Can someone please help me with this.:confused::confused::confused:

printf "Are you sure you want to reboot [y/n]"
read RESPONSE
if [ "$RESPONSE" = "Y" ]
then
        /sbin/reboot
else
        echo "response not Y"
fi

Thank you very much Corona.....

---------- Post updated at 01:39 PM ---------- Previous update was at 01:30 PM ----------

Am looking for the inbuilt command option of shutdown or reboot command instead of executing from script.

reboot is not an interactive command.

I'm not sure that I understand your question then.

You can take the script that Corona688 has posted and place it in the search path (eg, /usr/bin) and it becomes a 'command' that you can call from the CLI.

If we're on the wrong track please clarify.

Also, I assume that you have root access to do this?

Basically was looking for some confirmation option with command reboot / shutdown to avoid accidental reboot of server alike with copy and remove commands

cp -i /rm -i

but as said by corona688 that reboot is not interactive so will try to put the script on jumphost so that i can start working on it from jumphost itself .
Thanks Corona688 again and hicksd8 too.

When Corona688 says that the 'reboot' command is not interactive I think he means that it doesn't ask for confirmation. If you are root then that command (on most Unix flavors) will reboot the system (instantly) so prone to mistakes.

The 'shutdown' command is the standard way of doing it because you can specify a delay, send a warning to all logged-in users that the system is going down, etc. During the warning period the sequence could be interrupted if it was issued in error.

Another command you should be aware of is 'init' which changes the 'run level'.

 
 init 0
 

will close down the system

init 6

will reboot the system

init 5

will close down the system and power it off if your PSU supports it.

There are other 'run levels'; see the man page.

Most of the above relates to generic Unix speak. Depending on which flavour you're running, in my experience, 'init <run level>' is more likely to give you an orderly shutdown/reboot than the 'reboot' command.

'init' is the sysadmins short cut and NOT to be used by anyone else.