Need script to compare and redirect

Hi,
I have a file, sol_servers_global, which is list of all solaris global servers in my environment and another file,
solaris_non_global_zones_from_DB. I have a gateway server, from where all servers are contactable via ssh. I have collected name of zones running on these servers with below commands.

for i in `cat sol_servers_global`; do sudo ssh $i zoneadm list | grep -v global >>/var/tmp/all_zones; done

My basic idea is to prepare a script, which should -->
1- Capture zones running on servers listed on sol_servers_global (May be I can run for loop listed above)
2- Compare both files and list out zones which are not in solaris_non_global_zones_from_DB, but present in /var/tmp/all_zones and redirect to /var/tmp/servers_not_in_db.
3- Compare both files and list out zones which are not in /var/tmp/all_zones, but present in solaris_non_global_zones_from_DB and redirect to /var/tmp/servers_not_exist.
I was trying to compare it with below commands. If you have any easy and better compare tool, please suggest that too.

awk 'FNR==NR{a[$0];next} !($0 in a)' solaris_non_global_zones_from_DB /var/tmp/all_zones >>/var/tmp/servers_not_in_db
awk 'FNR==NR{a[$0];next} !($0 in a)' /var/tmp/all_zones solaris_non_global_zones_from_DB >>/var/tmp/servers_not_exist

I was doing it manually. It is very frequent so it takes long time to do it. If somebody can help me with script, it will be easy for me to do it fast.

Regards

you could try the -vxf pattern_file grep arguments instead of your awk code: eg:

while read server
do
   sudo ssh $server zoneadm list
done < sol_servers_global | grep -v global > /var/tmp/all_zones
 
grep -xvf solaris_non_global_zones_from_DB /var/tmp/all_zones > /var/tmp/servers_not_in_db
grep -xvf /var/tmp/all_zones solaris_non_global_zones_from_DB > /var/tmp/servers_not_exist

This script stops at first server only from list sol_servers_global and redirect zones of only first server to /var/tmp/all_zones.
Am I missing something in it ?

What shell are you using?

This seem to work fine in my tests with bash and ksh:

$ cat sol_servers_global 
server1
server2
server3
 
$ while read server
do
    echo Server $server read
done < sol_servers_global | grep -v global
Server server1 read
Server server2 read
Server server3 read