CLI Tricks: reboot/shutdown mollyguard function
Over on Twitter
I was having a discussion about creating a
mollyguard
to protect yourself from accidentally rebooting the wrong machine
by requiring you to type the hostname
of the machine you wanted to reboot.
If you need such,
you can add these functions to your
~/.bashrc
or
~/.profile
to create such a
reboot
function.
Note:
The function shown on Twitter had the logic reversed
so make sure you get the "=" and "!=" correct.
If
$1
equals
the hostname,
you want to proceed with the shutdown;
if they are
not equal
you want a warning.
If you run on OpenBSD
you can specify
doas
instead of
sudo
.