Re: How to get ssh to work in a loop

From: Mike Cross (mike.d.cross_at_btconnect.com)
Date: 12/01/03


Date: Mon, 1 Dec 2003 14:19:34 +0000 (UTC)

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

Mike

Peter Jones wrote:
> Dear group,
> I am having a problem getting ssh to work in a "for" loop. The script
> I am working on is run on a Solaris system and uses a host list to
> contact HP, AIX and Sun systems on the network to find out if any
> oracle filesystems are not largefile enabled. I have written the
> script for the sun systems which was quite easy as you only need to
> run one command and grep for largefiles. I am now trying to get the
> script to do the same for the HP systems which is proving more
> difficult.
>
> Here is the script for the HP systems:
>
> hp_systems() {
> for HOSTFILE in hp.hosts_temp
> do
> echo "\n** $HOSTFILE **"
> for HOST in `cat $BASEDIR/$HOSTFILE|awk '{print $1}'`
> do
> ping $HOST 1 > /dev/null
> if [ $? -ne 0 ]
> then
> echo "ERROR: $HOST not contactable."
> else
> echo $HOST > $LOGFILE
> ssh $HOST "cut -d ' ' -f2 /etc/mnttab | grep ora > /tmp/lrgfiles"
> for i in `ssh $HOST cat /tmp/lrgfiles`
> do
> echo $i >> $LOGFILE
> ssh $HOST fsadm -F vxfs $i | grep nolarge >> $LOGFILE
> done
> fi
> done
> done
> }
>
> In order to get the script to work for HP, I first have to get a list
> of mounted filesystems. I then have to run the fsadm command on each
> mounted filesystem by ssh to HP host and then creating a file called
> /tmp/lrgfiles. I then do a "for" loop and ssh to the host for each
> file in the /tmp/lrgfiles file. The outcome of this is that I end up
> doing loads of ssh to each host. There must be an easier way to do
> this - I'd like to have a for loop in which there is only one ssh to
> each host.
> Another problem I have is that each ssh connection attempt outputs an
> ssh banner to the screen - how do I stop ssh from outputting to the
> screen when run in a script?
>
> Many thanks
>
> Pete



Relevant Pages

  • ssh / keyless login problem
    ... OpenSSH_3.6.1p2, SSH protocols 1.5/2.0, OpenSSL 0x0090701f ... I am using rsync to backup my local host to a remote host over ssh. ... The first time the script runs after a long delay (ie overnight when the local ...
    (SSH)
  • Re: How to get ssh to work in a loop
    ... > script for the sun systems which was quite easy as you only need to ... Drop cat (useless use of this command). ... I believe other UNIX systems) is to continually ping if 'ping HOST' is ... Running multiple ssh calls to the same system in a loop ...
    (comp.unix.shell)
  • Re: Net::SSH::Perl bind socket problem
    ... > my script is supposed to to connect to every hosts (via a file named ... maybe the ssh object is not destroyed between the loops. ... ** define $ssh as my variable within the loop ...
    (perl.beginners)
  • Re: How do you save passwords for Git/GitHub?
    ... J> the repositories I need for my project Swift Linux. ... J> for my password EVERY TIME the script tries to download a repository. ... create SSH keyfiles. ... script that logs you into a host using that key, ...
    (Debian-User)