Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Remove ":" from the beginning of LD_LIBRARY_PATH definition:

export LD_LIBRARY_PATH=/opt/vmware/vma/lib64:/opt/vmware/vma/lib

Try to use #!/bin/bash instead of #!/bin/sh

You don't need to invoke this script by sh sandbox.sh. You can do chmod +x sandbox.sh and then you can invoke it as ./sandbox.sh

share|improve this answer
    
Thanks Mike, didn't see that typo. Using bash showed another error, looks like this script has additional issues since I edited it on a Windows box, I'm assuming it's got extra CR/LF that are breaking it. I should be able to re-create the script and test. Thanks for the help! –  MarkF Apr 12 '13 at 16:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.