awk, double variable, for loop and rsh

Hello folks,
I've a (perhaps) simple question.

In a text file I've :

server_name1: directory1
server_name2: directory2
server_name3: directory3
[...]

I want to make a loop that lets me connect and operate on every server:

rsh server_name1 "ls -l directory1"

I've tried with awk, but does not work (it doesn't export variables):

for n in `awk -F: {print $1}' text`
do 
   for m in `awk -F: {print $2}' text`
   do
      rsh $n "ls -l /$m"
   done
done

Any idea?

Thanks all
gb

mmm... that double loop is gonna call ls on each server for each directory; You probably want something like this:

while read s d ; do 
     rsh ${s%:} "ls -l $d"
done < text

The ${s%:} will get rid of the trailing colon.

thanks,
but this way it reads only first entry, not all.

It executes only:
rsh server_name1 "ls -l dir1"

Strange... do those directories on servers exist? Does the remote connection happen at all? Try rsh -v to switch on verbose mode.

it does not work at all now, cause it put cmd in bg before the read has been done... :S

> jobs
[3] +  Running                 while read n m ; do;remsh ${m%:} "ls -d /$n" &;done < text
[2] -  Running                 while read n m ; do;remsh ${m%:} "ls -d /$n" &;done < text
[1]    Running                 while read n m ; do;remsh ${m%:} "ls -d /$n" &;done < text

---------- Post updated at 11:55 AM ---------- Previous update was at 11:52 AM ----------

yes, they exists, and I've to use remsh, so no verbose mode possible.

---------- Post updated at 12:10 PM ---------- Previous update was at 11:55 AM ----------

arf... probably I've mistaped something the first time I execute my script, caus it works (not fine, cause it search everytime on everyserver everyline...)

so, this works (not fine):

for n in `awk -F: '{print $1}' text`; do
for m in `awk -F: '{print $2}' text`; do
remsh $n "ls -d /$m"
done
done

I prefer this one (works fine):

for n in `cat text`; do
ser = `echo $n | awk -F: '{print $1}'`
dir  = `echo $n | awk -F: '{print $2}'`
remsh $ser "ls -d /$dir"
done

thank you mirni (and I don't understand why your while doesn't work)

You got this mixed:

From your sample input, server was first, so the correct would be

while read n m ; do;remsh ${n%:} "ls -d /$m" ; done < text 

You can also try something like

awk -F": " ' { print "remsh "$1" \"ls -l /"$2"\"" | "sh" } '

Regards
Peasant.