title: Shell script for searching different on multiple servers
body: <p>I want to search different packages in multiple servers in Solaris 10. One file contains the package information, another file contains the server information.</p>
  
  <p>I have tried this:</p>
  
  <pre><code>bash-3.00# cat pk
  "VRTSvcs|VRTSvxfen"
  "SUNWfmd|SUNWfsmgtr"
  
  bash-3.00# cat ser
  mokshi
  niki
  </code></pre>
  
  <p>This is my script:</p>
  
  <pre><code>bash-3.00# cat tt
  #!/usr/bin/bash
  &gt;output
  for j in `cat ser`
  do
  for ip in `cat pk`
  do
  
  M=`ssh $j  "pkginfo |egrep $ip |cut -d \" \" -f7 "`;
  echo "$j " &gt;&gt;output
  echo "$M" &gt;&gt;output
  done
  done
  </code></pre>
  
  <p>The expected output is</p>
  
  <pre><code>cat output
  bash-3.00# cat output
  
  moksha
  
  VRTSvcs
  VRTSvcsag
  VRTSvcsea
  VRTSvxfen
  
  niki
  
  SUNWfmd
  SUNWfmdr
  SUNWfsmgtr
  </code></pre>
  
  <p>but when I run the script it is running twice like this:</p>
  
  <pre><code>bash-3.00# bash -x tt
  
  ++ cat ser
  
  + for j in '`cat ser`
  '
  ++ cat pk
  
  + for ip in '`cat pk`'
  ++ ssh mokshi 'pkginfo |egrep "VRTSvcs|VRTSvxfen" |cut -d " " -f7 '
  Password:
  + M='VRTSvcs
  VRTSvcsag
  VRTSvcsea
  VRTSvxfen'
  + echo 'mokshi '
  + echo 'VRTSvcs
  VRTSvcsag
  VRTSvcsea
  VRTSvxfen'
  + for ip in '`cat pk`'
  ++ ssh mokshi 'pkginfo |egrep "SUNWfmd|SUNWfsmgtr" |cut -d " " -f7 '
  Password:
  + M='SUNWfmd
  SUNWfmdr
  SUNWfsmgtr'
  + echo 'mokshi '
  + echo 'SUNWfmd
  SUNWfmdr
  SUNWfsmgtr'
  + for j in '`cat ser`'
  ++ cat pk
  + for ip in '`cat pk`'
  ++ ssh niki 'pkginfo |egrep "VRTSvcs|VRTSvxfen" |cut -d " " -f7 '
  Password:
  + M='VRTSvcs
  VRTSvcsag
  VRTSvcsea
  VRTSvxfen'
  + echo 'niki '
  + echo 'VRTSvcs
  VRTSvcsag
  VRTSvcsea
  VRTSvxfen'
  + for ip in '`cat pk`'
  ++ ssh niki 'pkginfo |egrep "SUNWfmd|SUNWfsmgtr" |cut -d " " -f7 '
  Password:
  + M='SUNWfmd
  SUNWfmdr
  SUNWfsmgtr'
  + echo 'niki '
  + echo 'SUNWfmd
  SUNWfmdr
  SUNWfsmgtr'
  </code></pre>
  
  <p>And I am getting output like this:</p>
  
  <pre><code>bash-3.00# cat output
  
  moksha
  
  VRTSvcs
  VRTSvcsag
  VRTSvcsea
  VRTSvxfen
  
  moksha
  
  SUNWfmd
  SUNWfmdr
  SUNWfsmgtr
  
  niki
  
  VRTSvcs
  VRTSvcsag
  VRTSvcsea
  VRTSvxfen
  niki
  
  SUNWfmd
  SUNWfmdr
  SUNWfsmgtr
  </code></pre>
  
  <p>The main goal of the script is that its take one server from server file and it has to search first line in package file.  The it has to take second server name from server name and it searches for second line in package file.</p>
  
  <p>please help me where I made a mistake.</p>