Last active
June 13, 2016 09:11
-
-
Save ilivessevili/393e007d9c53095de4c95071dda8dc62 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -eux | |
############################################################################################################ | |
# this script will check and auto start | |
# the selected vms in VMware ESXi 6.0 | |
# just put this script to /usr/sbin/ then | |
# append the following to the root's crontable then restart crond by pkill crond && crond | |
##min hour day mon dow command | |
#1 1 * * * /sbin/tmpwatch.py | |
#1 * * * * /sbin/auto-backup.sh | |
#0 * * * * /usr/lib/vmware/vmksummary/log-heartbeat.py | |
#*/5 * * * * /sbin/hostd-probe ++group=host/vim/vmvisor/hostd-probe | |
#*/1 * * * * /usr/sbin/check_and_auto_start_vms.sh "5.2" > /tmp/check_and_auto_start_vms.log 2>&1 | |
# | |
############################################################################################################ | |
#[ -n "$1" ] || echo "please input the vm name or vm keywords" || exit 1 | |
[ -n "$1" ] || exit 1 | |
KEYWORD="$1" | |
# check target vm state | |
####################### | |
# get target vm id by name | |
VM_IDs=$(vim-cmd vmsvc/getallvms | awk "/$KEYWORD/ {print \$1}") | |
for id in $VM_IDs; do | |
vim-cmd vmsvc/power.getstat $id | grep -iq 'Powered off' | |
if [ $? -eq 0 ]; then | |
echo "this vm is powered off now power it on ..." | |
echo vim-cmd vmsvc/power.on $id | |
fi | |
echo "This is vm identified by vmid: $id is already powered on skipping..." | |
done | |
echo '*********************************' | |
echo "auto start selected vms done!" | |
echo '*********************************' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment