Run for loop only if the looping variable exists in bash scripting?

Joined
Apr 16, 2023
Messages
149
Reaction score
16
Credits
1,460
Code:
#Declare the path
PATH_GF='/home/srvrname/srvrname/bin/asadmin'
domainArray=("dom1" "dom2" "dom3" "dom4" "dom5" "dom6" "dom7")
for domain in $domainArray; do
    $PATH_GF stop-domain $domain
done

echo "All Domains Have Been Stopped"

i="0"

while [ $i -lt 10 ]; do
    echo "Waiting some time" &
    i=$(($i + 1))
done

for domain in $domainArray; do
    $PATH_GF start-domain $domain
done

echo "All Domains Have Been Started Again"

I want to run stop-domain only when the domain exists in that server (so that I don't get erroneous results). How do I achieve it?
I'm doing this because I am going to put this script into every server. And each have different domain names.
 


Top