Re: How to get ssh to work in a loop
From: Peter Jones (petejones1974_at_hotmail.com)
Date: 12 Dec 2003 03:11:04 -0800
I'm still unable to get the loop to work.
I run the following command to create a file called /tmp/lrgfiles on
the remote server:
ssh $HOST "cut -d ' ' -f2 /etc/mnttab | grep ora > /tmp/lrgfiles"
I then want to perform some processing on this file on the remote
server but get the results on the local system.
Below is the for loop that I want to perform on the remote server
using ssh to connect. How do I get this loop to run using ssh and how
can I get the output back to the local system?
for i in `cat /tmp/lrgfiles`
fsadm -F vxfs $i | grep nolarge > /dev/null
if [ $? = 0 ]
done >> /tmp/output
All help greatly appreciated.
Kevin Rodgers <email@example.com> wrote in message news:<3FCCBF7F.firstname.lastname@example.org>...
> [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 ...