Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ESXi vm shutdown script
#!/bin/sh
#Vmid Name File Guest OS Version Annotation
#1 production-w7 [Storage] production-w7/general-w7.vmx windows7_64Guest vmx-08
#13 dev-centos [Storage] dev-centos/dev-centos.vmx centos64Guest vmx-08
#19 production-centos-ups [Storage] production-centos-ups/production-centos-ups.vmx centos64Guest vmx-08
#21 testing-router [Storage] testing-router/testing-router.vmx otherGuest vmx-08
#22 testing-w7 [Storage] testing-w7/testing-w7.vmx windows7_64Guest vmx-08
#23 testing-xp [Storage] testing-xp/testing-xp.vmx winXPProGuest vmx-08
#28 testing-w2k8-2 [Storage] testing-w2k8-2/testing-w2k8-2.vmx windows7Server64Guest vmx-08
#4 testing-w2k8 [Storage] testing-w2k8/testing-w2k8.vmx windows7Server64Guest vmx-09
#6 production-centos [Storage] production-centos/production-centos.vmx centos64Guest vmx-08
# shutdown production first
echo "Shutting down production..."
vim-cmd vmsvc/power.shutdown 6
vim-cmd vmsvc/power.shutdown 1
# shutdown dev
echo "Shutting down dev..."
vim-cmd vmsvc/power.shutdown 13
# shudown testing
echo "Shutting down testing..."
vim-cmd vmsvc/power.shutdown 21
vim-cmd vmsvc/power.shutdown 22
vim-cmd vmsvc/power.shutdown 23
vim-cmd vmsvc/power.shutdown 28
vim-cmd vmsvc/power.shutdown 4
# leave the ups station running to continue exeuting this script
# sleep for X to ensure everything shutdown
echo "Sleeping for 300 seconds..."
sleep 300s
# shutdown the esx server
echo "Shutting down self..."
poweroff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.