I'm trying to configure the APC Network Shutdown script for 3 ESX hosts, and it doesn't seem like I can run my test script on my vMA appliance. I'm trying to verify I've set it up correctly using a bunch of echo commands in a test file named 'sandbox.sh'.
Here's my script:
#!/bin/sh
#IFS=$(echo -en "\n\b")
unset IFS
export LD_LIBRARY_PATH=:/opt/vmware/vma/lib64:/opt/vmware/vma/lib
export PERL_LWP_SSL_VERIFY_HOSTNAME=0
#Hosts
#vMA is on host .131, so it will appear last
hosts=( 192.168.47.130 192.168.47.132 192.168.47.131 )
ups_vm="vSphere Management Assistant \(vMA\)"
mail_vms="Test"
dc_vms="CITRIX"
#search for exchange servers first, and shut down
echo "Searching for Email VMs to shut down..."
for host in ${hosts[@]}; do
echo $host
source /opt/vmware/vma/bin/vifptarget -s $host
for i in `vmware-cmd -l | egrep $mail_vms`; do
if [ `vmware-cmd $i getstate | egrep -c "on"` -eq 1 ]; then
echo "I would have shut down EMAIL server $i"
fi
done
source /opt/vmware/vma/bin/vifptarget -c
done
#then shutdown all other VMs besides DCs and vMA
echo "Searching for VMs to shut down\(besides DC and vMA\)..."
for host in ${hosts[@]}; do
echo $host
source /opt/vmware/vma/bin/vifptarget -s $host
for j in `vmware-cmd -l`; do
if [ `vmware-cmd $j getstate | egrep -c "on"` -eq 1 ]; then
echo $j
if [ `echo $j | egrep -c $ups_vm` -eq 1 ]; then
echo "Skip shut down of VMA"
elif [ `echo $j | egrep -c $dc_vms` -eq 1 ]; then
echo "Skipping shutting down DC for now"
else
echo "I would have shut down $j"
fi
fi
done
source /opt/vmware/vma/bin/vifptarget -c
done
#now shutdown DCs
echo "Searching for domain controller VMs to shut down"
for host in ${hosts[@]}; do
echo $host
source /opt/vmware/vma/bin/vifptarget -s $host
for k in `vmware-cmd -l | egrep $dc_vms`; do
if [ `vmware-cmd $k getstate | egrep -c "on"` -eq 1 ]; then
echo "I would have shut down DC $k"
fi
done
source /opt/vmware/vma/bin/vifptarget -c
done
unset IFS
I SSH into the vMA appliance and use the following command to try to run the script:
sh sandbox.sh
Output:
': not a valid identifiert: `LD_LIBRARY_PATH
: command not found
: command not found:
Searching for Email VMs to shut down...
(192.168.47.130 192.168.47.132 192.168.47.131)
'andbox.sh: line 21: syntax error near unexpected token `do
'andbox.sh: line 21: `for i in `vmware-cmd -l | egrep $mail_vms`; do
Any idea what's going on? Am I running this script correctly?
Remove ":" from the beginning of LD_LIBRARY_PATH definition:
Try to use
#!/bin/bash
instead of#!/bin/sh
You don't need to invoke this script by
sh sandbox.sh
. You can dochmod +x sandbox.sh
and then you can invoke it as./sandbox.sh