用alias命令避免虚拟机关机

@Linux

用alias命令避免虚拟机关机

下班时候关树莓派,poweroff命令一敲,才发现把SSH远程的虚拟机给关了。给管理员发邮件才重新开机。想了一下,应该把虚拟机上的halt、poweroff、shutdown命令都给禁用掉,只留一个reboot。
但是我一直用的是root用户,貌似也没法禁用某个命令。

要不用alias把关机的命令改成别的?

halt命令可以用halt -w来代替,不执行halt命令,也就写个记录。

[root@test ~]# halt --help
halt [OPTIONS...]

Halt the system.

     --help      Show this help
     --halt      Halt the machine
  -p --poweroff  Switch off the machine
     --reboot    Reboot the machine
  -f --force     Force immediate halt/power-off/reboot
  -w --wtmp-only Don't halt/power-off/reboot, just write wtmp record
  -d --no-wtmp   Don't write wtmp record
     --no-wall   Don't send wall message before halt/power-off/reboot

poweroff命令也一样,可以用poweroff -w来代替。

[root@test ~]# poweroff --help
poweroff [OPTIONS...]

Power off the system.

     --help      Show this help
     --halt      Halt the machine
  -p --poweroff  Switch off the machine
     --reboot    Reboot the machine
  -f --force     Force immediate halt/power-off/reboot
  -w --wtmp-only Don't halt/power-off/reboot, just write wtmp record
  -d --no-wtmp   Don't write wtmp record
     --no-wall   Don't send wall message before halt/power-off/reboot

但是shutdown命令只能用shutdown -k来代替,还是会出提示,有点吓人。

[root@test ~]# shutdown --help
shutdown [OPTIONS...] [TIME] [WALL...]

Shut down the system.

     --help      Show this help
  -H --halt      Halt the machine
  -P --poweroff  Power-off the machine
  -r --reboot    Reboot the machine
  -h             Equivalent to --poweroff, overridden by --halt
  -k             Don't halt/power-off/reboot, just send warnings
     --no-wall   Don't send wall message before halt/power-off/reboot
  -c             Cancel a pending shutdown

还是改成echo命令吧,嘿嘿!编辑.bashrc文件,alias添加几行:

alias halt='echo "Are you OK??"'
alias poweroff='echo "Are you OK??"'
alias shutdown='echo "Are you OK??"'

修改之后要source一下才能生效。居然报错?

[root@test ~]# source .bashrc
if: Expression Syntax.
then: Command not found.
root@test ~]# source /root/.bashrc
if: Expression Syntax.
then: Command not found.

百度一下,原来是shell的问题,修改一下默认shell即可。

[root@test ~]# echo $SHELL
/bin/tcsh
[root@test ~]# chsh -s /bin/bash
Changing shell for root.
Shell changed.
[root@test ~]# echo $SHELL
/bin/bash
[root@test ~]# source .bashrc
[root@test ~]# 

输入命令之后返回Are you OK?,完全无害。

[root@test ~]# poweroff
Are you OK??
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mybrightday

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值