Tripp Lite SV20KM1P1B Users Guide for PowerAlert Network Shutdown Agent PANSA - Page 17

APPENDIX A - Sample Scripts

Page 17 highlights

APPENDIX A - Sample Scripts 2. Shutdown VMs on ESXi Server(s) This script is used to forcibly shut down the virtual machines on one or more ESXi servers, and then shut down the ESXi server(s). This method does not rely upon the pre-configured shutdown settings on each server to shut down the virtual machines. This script is typically used when performing a shutdown for virtual machines in a high availability (HA) cluster. Linux Script: shutdownvms.sh #!/bin/sh LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/vmware/vma/lib64:/opt/vmware/vma/lib export LD_LIBRARY_PATH export PERL_LWP_SSL_VERIFY_HOSTNAME=0 SAVEIFS=$IFS IFS=$(echo -en "\n\b") # Use this script to shutdown ESXi hosts in an HA Cluster # This script requires that the ESXi hosts are controllable by the vMA. # You can check if the servers are added to the vMA by running # the command "vifp listservers". # You can add the ESXi servers by running the command # "vifp addserver " from the vMA terminal # Designate the ESXi host(s) to shut down. # User input required- Enter IP addresses for all ESXi hosts in the cluster. hosts=(10.0.0.25 10.0.0.26 10.0.0.27 10.0.0.28) # User input required- Input the exact virtual machine name for the vMA # use \ to escape special characters in the name, e.g. \( ups_vm="vSphere Management Assistant \(vMA\)" # Change directory to directory containing vicfg script files cd /usr/bin for host in ${hosts[@]}; do echo $host source /opt/vmware/vma/bin/vifptarget -s $host # Be sure to change the username and password parameters before use # User input required- input the username and password for the hosts for i in `vmware-cmd -l --username xxxx --password xxxx`; do if [ `vmware-cmd $i getstate | egrep -c "on"` -eq 1 ]; then echo $i if [ `echo $i | egrep -c $ups_vm` -eq 1 ]; then echo "Skip shut down of VMA" else echo "Shutting down $i" vmware-cmd "$i" stop soft fi fi done source /opt/vmware/vma/bin/vifptarget -c # User input required- input the username and password for the hosts # Do NOT change the $host text # Trigger the host server to shut down. Be sure to change the username # and password parameters before use. ./vicfg-hostops --server $host --username xxxxx --password xxxxx --operation shutdown --force done 17

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

17
APPENDIX A – Sample Scripts
2. Shutdown VMs on ESXi Server(s)
This script is used to forcibly shut down the virtual machines on one or more ESXi servers, and then shut down the ESXi server(s). This
method does not rely upon the pre-configured shutdown settings on each server to shut down the virtual machines. This script is typically
used when performing a shutdown for virtual machines in a high availability (HA) cluster.
Linux Script: shutdownvms.sh
#!/bin/sh
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/vmware/vma/lib64:/opt/vmware/vma/lib
export LD_LIBRARY_PATH
export PERL_LWP_SSL_VERIFY_HOSTNAME=0
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
# Use this script to shutdown ESXi hosts in an HA Cluster
# This script requires that the ESXi hosts are controllable by the vMA.
# You can check if the servers are added to the vMA by running
# the command "vifp listservers".
# You can add the ESXi servers by running the command
# "vifp addserver <host IP>" from the vMA terminal
# Designate the ESXi host(s) to shut down.
# User input required- Enter IP addresses for all ESXi hosts in the cluster.
hosts=(10.0.0.25 10.0.0.26 10.0.0.27 10.0.0.28)
# User input required- Input the exact virtual machine name for the vMA
# use \ to escape special characters in the name, e.g. \(
ups_vm="vSphere Management Assistant \(vMA\)"
# Change directory to directory containing vicfg script files
cd /usr/bin
for host in ${hosts[@]}; do
echo $host
source /opt/vmware/vma/bin/vifptarget -s $host
# Be sure to change the username and password parameters before use
# User input required- input the username and password for the hosts
for i in `vmware-cmd -l --username xxxx --password xxxx`; do
if [ `vmware-cmd $i getstate | egrep -c "on"` -eq 1 ]; then
echo $i
if [ `echo $i | egrep -c $ups_vm` -eq 1 ]; then
echo "Skip shut down of VMA"
else
echo "Shutting down $i"
vmware-cmd "$i" stop soft
done
source /opt/vmware/vma/bin/vifptarget -c
# User input required- input the username and password for the hosts
# Do NOT change the $host text
# Trigger the host server to shut down. Be sure to change the username
# and password parameters before use.
./vicfg-hostops --server $host --username xxxxx --password xxxxx --operation shutdown --force
done