Help with script to reach remote servers

new3=`cat /tmp/list3`

for pol in "$new3" $(su - dbadmin -c "ssh $new3 '/usr//llist'");
do export policy=`echo $pol`;  su - dbadmin -c "ssh $x '/usr/policycmd $policy -L |grep -i active; echo $policy'">>/tmp/listxyz;done

I am having trouble with this testscript as the file list3 has two names in it, servera and serverb. I want this script to ssh to servera and run the /usr/llist command and then as dbadmin ssh again to servera and then run the /usr/policycmd. Then it should go to serverb and do the same two sshs and run the commands.

But when I debugged it, I found that the script will ssh to servera and then after it runs the /usr/llist command it will ssh to serverb. I am not sure how to make it only ssh to servera. After the commands have completed I want it to do the same for serverb.

Any suggestions? This seemed easy at first but is difficult. Do you need to use an array to do this? If I don't use the /tmp/list3 file and just use one server name, (such as assigning new3=servera the commands work just fine. But I want the same commands run for each server in the list.
Confused!

where does $x var get set?

Try putting your code into a framework like this, and repost:

rm -f /tmp/listxyz
while read policy; do
  # do something
  export $policy
  # do something
  echo $policy >> /tmp/listxyz
done < /tmp/list3