Our server names either have a dash (-) or underscore (_)
file.txt consists of:
irl-iv-host01
irl-vm-host02
irl-rv-host01
irl-sd-host01
Objective is to check if the server exists and then run the next command.
So this command right here is where we check if the server exist on the list of zones.
var1=`ssh support@1.2.3.4 cfgactvshow | grep -i "$host" | awk '{print $2}'`
However, there are instances that the host configured on the list of zones are different, sometimes its irl-iv-host01 or irl_iv_host01 or irl-iv_host01 or even irl_iv-host01
so what i want is to check if host irl-iv-host01 is on the list of zones whether it's name is any of these irl-iv-host01, irl_vm_host01, irl-iv_host01, irl_iv-host01
and then use it for another command that checks the zonename which is
ssh support@1.2.3.4 zoneshow "$var1"
Now, if in the event that during the grep process the result is multiple, i guess or maybe it will be stored to another variable which we can also use like the sample below.
Example if multiple output:
ssh support@1.2.3.4 cfgactvshow | grep -i "$host" | awk '{print $2}'
zone1_irl-iv-host01
zone2_irl-iv-host01
zone3_irl-iv-host01
ssh support@1.2.3.4 zoneshow zone1_irl-iv-host01
ssh support@1.2.3.4 zoneshow zone2_irl-iv-host01
ssh support@1.2.3.4 zoneshow zone3_irl-iv-host01
The question is, is there a simpler way to do it?
I just feel i'm running around the bush
while read -r host;
do
withunderscore=`echo $host | sed 's/-/_/g'`
var1=`ssh support@1.2.3.4 command | grep "$host"`
var2=`ssh support@1.2.3.4 command | grep "$withunderscore"`
if var1 is not empty then run the command but if it is, test var2.
If var2 is not empty then run the command but if it is, echo "both vars are empty.
done < file.txt
I would appreciate any help. thank you.