Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 ''.

Here's my script:

#IFS=$(echo -en "\n\b")
unset IFS
export LD_LIBRARY_PATH=:/opt/vmware/vma/lib64:/opt/vmware/vma/lib

#vMA is on host .131, so it will appear last
hosts=( )
ups_vm="vSphere Management Assistant \(vMA\)"

#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"
source /opt/vmware/vma/bin/vifptarget -c

#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"
echo "I would have shut down $j"
source /opt/vmware/vma/bin/vifptarget -c

#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"
source /opt/vmware/vma/bin/vifptarget -c

unset IFS

I SSH into the vMA appliance and use the following command to try to run the script:



': not a valid identifiert: `LD_LIBRARY_PATH
: command not found
: command not found:
Searching for Email VMs to shut down...
' line 21: syntax error near unexpected token `do
' 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
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 You can do chmod +x and then you can invoke it as ./

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


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.