Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with rsh command in a loop while 1

Status
Not open for further replies.

Barn

Technical User
Feb 22, 2002
37
FR
I have a text file (file.txt) with these entries:
SERVER1
SERVER2

I do this in script.ksh

cat file.txt|while read server
do
rsh $server –l myuser ls
done


the loop break after the first rsh without error
if instead I do this:

cat file.txt|while read server
do
echo rsh $server –l myuser ls
done

The two lines are treated

It works with a "for" loop too

for server in `cat file.txt`
do
rsh $server –l myuser ls
done

what's wrong with rsh command in a while loop?
Thanks in advance
 
I'm not sure why, but I've never had it work either. I get the same thing with running commands via ssh as well.

My workaround is to have my loop write another script, with all of the rsh/ssh commands, then after the loop terminates, run that new script.
 
I have come across this behaviour.

Its due to the rsh breaking stdin for the read (for its own use).

In this case you can code around the problem in the following way.

Code:
exec 3< file.txt
while read -u3 server
do
   rsh $server –l myuser ls
done

Hope this helps.

Best Regards, Peter.
 

Thanks to both of you!
The both solutions work well.

I retain the solution of Peter and so I give him a star.

Bye. Barn.
IBM Certified -- Am I?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top