Wednesday 20 June 2018

Confirmation message before shutdown/reboot [Linux]

What:

Linux server

Problem:

When you're connected to multiple servers from your computer, you might type shutdown command in the incorrect window, causing a lot of trouble.

Solution:

Simplest solution I came up with is issuing sleep command before shutdown, it won't break any automated scripts you might have and stops from accidental shutdowns.

In .bashrc add the following aliases.
alias reboot='echo "Rebooting $(hostname) in 10 secs. Press ctrl+c to cancel"; sleep 10 && reboot'
alias poweroff='echo "Shutting down $(hostname) in 10 secs. Press ctrl+c to cancel"; sleep 10 && poweroff'
alias shutdown='echo "Shutting down $(hostname) in 10 secs. Press ctrl+c to cancel"; sleep 10 && shutdown'
Now log off and back on and test it.

No comments:

Post a Comment