I have a bash array of hosts.
a_hosts=( "host1.q.d.n",
"host2.q.d.n",
"host3.q.d.n",
...
"hostN.q.d.n"
)
I need to compare a specific file on each host with the same file on all of the other hosts.
diff host1.file host2.file
diff host1.file host3.file
...
diff host1.file hostN.file
diff host2.file host3.file
...
diff host2.file hostN.file
...etc.
I have ideas based on this solution, but I keep backing myself into a corner when I try to loop through loopN-1
inside of a loop through loopN
. I almost think I have to duplicate the array, and keep the two arrays synchronized. But, that's yet another loop.
Has anyone come up with an elegant solution to this kind of loop manipulation?
EDIT 1:
I'm experimenting with this.
# Create two loop arrays.
a_outer_loop=a_hosts
a_inner_loop=a_hosts
# Iterate through outer loop.
for s_fqdn1 in ${a_outer_loop[@]}
do
# Pop the first item of the inner loop. (Index 0)
a_inner_loop=( ${a_inner_loop[@]:1:} )
# Loop through the popped inner loop.
for s_fqdn2 in ${a_inner_loop[@]}
do
diff s_fqdn1.file s_fqdn2.file
done
done
EDIT 2:
Ack! Sorry, my fault for oversimplifying my example. If my list of hosts were really host1
, host2
, ..., hostN
, this would be a much simpler problem. Sadly, I have several varieties of FQDNs to deal with, in several domains, so no solution as easy as host$i
will work. Good news is: I think I've got something that will work.