vsphere esxi设置定时自动关机脚本

步骤如下

[root@localhost:~] cat /etc/rc.local.d/local.sh 
#!/bin/sh

# local configuration options

# Note: modify at your own risk!  If you do/use anything in this
# script that is not part of a stable API (relying on files to be in
# specific places, specific tools, specific output, etc) there is a
# possibility you will end up with a broken system after patching or
# upgrading.  Changes are not supported unless under direction of
# VMware support.

# Note: This script will not be run when UEFI secure boot is enabled.
在exit0之前添加以下内容
/bin/kill $(cat /var/run/crond.pid)
下面的时间是UTC时间,日常使用的是北京时间,需要进行转换
/bin/echo '25 05 * * * /vmfs/volumes/datastore1/autoshutdown.sh' >> /var/spool/cron/crontabs/root
重启cron进程(将加载修改后的root文件)
/usr/lib/vmware/busybox/bin/busybox crond
exit 0

注意:
1、修改完/etc/rc.local.d/local.sh文件后,需要执行auto-backup命令把local.sh文件保存,否则重启后会丢失。
2、重启机器或者手工执行一次local.sh脚本才能生效
(sh /etc/rc.local.d/local.sh)

关机脚本:

vi /vmfs/volumes/datastore1/autoshutdown.sh
#!/bin/bash
vim-cmd vmsvc/power.off 1  //后面数字指虚拟机id
/sbin/poweroff

相关命令:

//查询所有已配置的虚拟机,可获得VMID
vim-cmd vmsvc/getallvms
//通过VMID查询相应的虚拟机的当前开关机状态
vim-cmd vmsvc/power.getstate VMID
//发送关机信号(命令),但操作系统未必会真正关机
vim-cmd vmsvc/power.shutdown VMID
//直接关机(相当于关电源)
vim-cmd vmsvc/power.power VMID
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值