Re: How to get ssh to work in a loop

From: Kevin Rodgers (
Date: 12/02/03

Date: Tue, 02 Dec 2003 09:36:15 -0700

[Please don't top-post.]

Mike Cross wrote:

> The for loop scrambles stdin, which upset, ssh/rsh, I get around ths by
> using while loop:
> while read line
> do
> ..
> ..
> rsh $line date
> ..
> done < file
> works OK

No, it doesn't. The body of the while ... done loop inherits its file
descriptors, and the rsh command still consumes all of the remaining
data in standard input. The way to get around this problem is to
redirect rsh's standard input

        rsh $host ... < /dev/null

or use the command line option provided for this purpose

        rsh -n $host ...

Kevin Rodgers

Relevant Pages

  • Re: need some help
    ... an entire line from standard input, ... simply call this function in a loop, ... int ggetsreturns 0 for success, EOF for eof, and positive ...
  • Re: Command line
    ... end loop; ... machine) a compiler error. ... > as standard input, or you could just pick up argument ...
  • Re: Standard input
    ... standard input of the fortran program. ... The second loop does not terminate: ... This can easily be solved by introducing a keyword like "QUIT" - ...
  • Reading the while standard input into a String
    ... whole contents of the standard input into some place in memory, ... character by character into a temporary buffer, ... for J in To'Range loop ...
  • Re: program calls rcmd() twice, _second_ call works for root but not normal users
    ... David Schwartz wrote: ... >>All of this was within the loop over target hosts. ... >>in the first place since rsh runs perfectly well without it in the limited ... I'm still not clear what the setuid(uid) was doing since the uid value ...