Operating System - HP-UX
1834149 Members
2256 Online
110064 Solutions
New Discussion

Re: remsh break the while loop

 
SOLVED
Go to solution
jose-kl
Advisor

remsh break the while loop

I working with posix shell and trying to run remsh
command in a while loop but the while loop break after
the first iteration of the loop .

Any idea why it happen ?

System is HPUX11.11

For example :

Assume I have 3 lines in /tmp/test

# cat /tmp/test
line1
line2
line3

#cat /tmp/test | while read line
>do
>remsh hostname1 date
>done
Thu May 17 14:03:43 IST 2007

if the other hand if I'm running the date command on local machine (not via remsh )
it runs the loop 3 times as expected .

# cat /tmp/test | while read line
> do
> date
> done
Sun May 20 23:25:54 METDST 2007
Sun May 20 23:25:54 METDST 2007
Sun May 20 23:25:54 METDST 2007


Thanks for any reply

Jose

3 REPLIES 3
James R. Ferguson
Acclaimed Contributor
Solution

Re: remsh break the while loop

Hi Jose:

You need to add the '-n' switch:

while read line
do
remsh hostname1 -n date
done < /tmp/test

Notice that I eliminated the extra 'cat' process and performed the read directly.

The 'remsh' manpages note that, "By default, remsh reads its standard input and sends it to the remote command because remsh has no way to determine whether the remote command requires input. The -n option redirects standard input to remsh from /dev/null."

Hence the behavior you see.

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: remsh break the while loop

Your example doesn't show any use of $line, was that while-loop really needed? (Perhaps the name of each host?)

Note if the size of the file "test" is small, you can also use a for-loop:
for line in $(< /tmp/test ); do
remsh hostname1 -n date
done
jose-kl
Advisor

Re: remsh break the while loop

Hello James,

Great.

I add the "-n" and it work fine .

Thanks,
Jose