# ESXI # Esxi 开机脚本 #/bin/bash # author:jerry # create date:2017-8-29 # last update:2018-7-30 status=`vim-cmd /hostsvc/hostsummary | grep inMaintenanceMode|cut -c 27` [ $status == "t" ] && vim-cmd hostsvc/maintenance_mode_exit 1&> /dev/null for on in `vim-cmd vmsvc/getallvms |awk '{print $1}'|tail -n 12` do if [ $on -eq 11 ] then continue else vim-cmd vmsvc/power.on $on sleep 30 fi done
# Esxi 关机脚本 #!/bin/sh # author:jerry # create date:2017-7-27 # last update:2018-7-30 off=`esxcli vm process list|grep World |awk '{print $3}'|wc -l` status=`vim-cmd /hostsvc/hostsummary | grep inMaintenanceMode|cut -c 27` if [ $off == 0 ] ;then [ $status == "f" ] && vim-cmd hostsvc/maintenance_mode_enter 1&> /dev/null && sleep 10 && halt || halt else hostsum=`vim-cmd vmsvc/getallvms|awk 'NR>1{print $1}'|wc -l` vim-cmd vmsvc/getallvms|awk 'NR>1{print $1}'>tmp.txt for i in `seq 1 $hostsum` do vid=`sed -n "$i p" ./tmp.txt` on=`vim-cmd vmsvc/power.getstate $vid |tail -1|awk '{print $2}' 2&>/dev/null` if [ $on == on ] ;then vim-cmd vmsvc/power.shutdown $vid 1&>/dev/null sleep 5 fi done rm -rf ./tmp.txt off=`esxcli vm process list|grep World|awk '{print $3}'|wc -l` if [ $off == 0 ] ;then vim-cmd hostsvc/maintenance_mode_enter 1&> /dev/null sleep 10 halt else ps |grep vmx|awk '{print $2}' |uniq >tmp.txt on=`ps |grep vmx|awk '{print $2}' |uniq |wc -l` for i in `seq 1 $on` do hostid=`sed -n " $i p " ./tmp.txt` kill $hostid 1&> /dev/null done rm -rf ./tmp.txt vim-cmd hostsvc/maintenance_mode_enter 1&> /dev/null sleep 10 halt fi fi (责任编辑:IT) |