How to require 'reboot' command to be interactive?

How to require ‘reboot’ to be interactive?

One too many times I’ve dropped a reboot in the localhost thinking I was logged into a server.

2 Likes
sudo tee /etc/profile.d/custom.sh << "EOF"
reboot() {
    read -p "reboot ${HOSTNAME}? (y/N): "
    if [ "${REPLY}" = "y" ]
    then sudo reboot "${@}"
    fi
}
EOF
. /etc/profile

An alternative method to work with sudo reboot:

sudo tee /usr/local/sbin/reboot << "EOF"
#!/usr/bin/bash
read -p "reboot ${HOSTNAME}? (y/N): "
if [ "${REPLY}" = "y" ]
then /usr/sbin/reboot "${@}"
fi
EOF
sudo chmod +x /usr/local/sbin/reboot
hash -r
3 Likes

thanks brother!

Calling the hostname was a good idea

2 Likes

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.