iT邦幫忙

0

if shell script 的判斷式該怎麼改寫

有兩個Domain 每個Domain有兩台server 做cluster
想寫個自動化 當程式更新需要做server 重起 script
是從master連ssh進到各台server
內容目前如下 因為是用if寫的server只會一台一台重啟 有什麼辦法可以把程式改成
同時重啟A1和B1 然後在各自判斷domain底下某一台啟好 再重啟第二台

#part of ADomain
if [ -z "條件1" ]; then
echo "ADomain don't Restart" > /tmp/startADomain.log
else
echo "ADomain Restart" > /tmp/startADomain.log
ssh root@10.0.0.1 < /tmp/A1.sh
fi

if [[ -n cat /tmp/startA1.log | grep "services are lazy" | grep "INFO" ]]; then
echo -e "\e[1;34;40m startA1 done \e[0m"
ssh root@10.0.0.2 < /tmp/A2.sh
else
echo -e "\e[1;35;40m Can not find A1 services are lazy in the Log file. \e[0m"
fi

if [[ -n cat /tmp/startA2.log | grep "services are lazy" | grep "INFO" ]]; then
echo -e "\e[1;34;40m A2Server done \e[0m"
else
echo -e "\e[1;35;40m Can not find A2 services are lazy in the Log file. \e[0m"
fi

#part of BDomain
if [ -z "條件2" ]; then
echo "BDomain don't Restart" > /tmp/startBDomain.log
else
echo "BDomain Restart" > /tmp/startBDomain.log
ssh root@10.0.0.3 < /tmp/B1.sh
fi

if [[ -n cat /tmp/startB1.log | grep "services are lazy" | grep "INFO" ]]; then
echo -e "\e[1;34;40m startB1 done \e[0m"
ssh root@10.0.0.4 < /tmp/B2.sh
else
echo -e "\e[1;35;40m Can not find B1 services are lazy in the Log file. \e[0m"
fi

if [[ -n cat /tmp/startB2.log | grep "services are lazy" | grep "INFO" ]]; then
echo -e "\e[1;34;40m B2Server done \e[0m"
else
echo -e "\e[1;35;40m Can not find B2 services are lazy in the Log file. \e[0m"
fi

尚未有邦友回答

立即登入回答