rsh command in a while loop

Hi ,

reading a "file1" with 2 data in each line (VAR1 and VAR2) , i'm using a while loop like this :

cat file1|awk '{print $1,$2}'|while read VAR1 VA2
do
echo $VAR1
echo $VAR2
done

as this example shows , it works but if between do and done i use
a "rsh" command , the script reads only the first line and exits.

It works just like if it change to another memory space , maybe i should use "exec" command but i don't know how !!!!!

Someone has an idea ????

thanks in advance

Christian

Don't know what shell you were using - the code you posted did not work in ksh - and got only the first variable in sh. Csh didn't work at all.

This works:

#!/bin/ksh
while read -r eachline
do
VAR1=`echo $eachline|awk '{print $1}'`
VAR2=`echo $eachline|awk '{print $2}'`
rsh -l $VAR2 $VAR1 uptime
done < ./file1
exit

format of file1
firstsystemname useracccount
seconsystem useraccount
thirdsystem useraccount

Thanks ,

i'm using AIX with ksh too ,

i tried your code and it does the same thing as mine , after reading the first line of "file1" and executing the rsh command , it doesn't continue on next line !

if i comment the "rsh" line , the loop is ok

i don't understand anything !!!

christian

Maybe someone with AIX access can assist. Mine was run on Solaris.

That's right , i've found !!

Thanks again for your help !!!! ( and PERDERABO changepass script)

christian

modifications in red

#!/bin/ksh

exec 4>&1

while read -r eachline
do
VAR1=`echo $eachline|awk '{print $1}'`
VAR2=`echo $eachline|awk '{print $2}'`

rsh $VAR1 -l $VAR2 uptime >&4 2>&4 |&

wait

done < ./file1
exit

format of file1
firstsystemname useracccount
seconsystem useraccount
thirdsystem useraccount

Gack! That is a terrible solution. You don't want to use a coprocess for this. Your whole problem is that you need -n on the rsh. But here is what I would have done...

#! /usr/bin/ksh
typeset -R19 fhost
exec < file
while read host user ; do
     fhost=${host}:
     echo "$fhost $(rsh $host -l $user -n uptime)"
done
exit 0

Thanks a lot !

"how to do it simple when i can do it very complicated" is my saying (joke)

my script is quite finish and also more legible !

christian