vMA 上的 APC 网络关闭脚本

vMA 上的 APC 网络关闭脚本

我正在尝试为 3 个 ESX 主机配置 APC 网络关闭脚本,但似乎无法在 vMA 设备上运行测试脚本。我尝试使用名为“sandbox.sh”的测试文件中的一组 echo 命令来验证我是否已正确设置它。

这是我的脚本:

#!/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

我通过 SSH 进入 vMA 设备并使用以下命令尝试运行脚本:

sh sandbox.sh

输出:

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

知道发生了什么吗?我是否正确运行了此脚本?

答案1

从 LD_LIBRARY_PATH 定义的开头删除“:”:

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

尝试使用#!/bin/bash而不是#!/bin/sh

您不需要通过 来调用此脚本sh sandbox.sh。您可以执行chmod +x sandbox.sh然后以如下方式调用它./sandbox.sh

相关内容