Re: ssh ssh
am 30.03.2008 16:27:31 von hjp-usenet2On 2008-03-27 18:47, jammer
> Here is my next attempt:
>
> #!/bin/perl
>
> use strict;
>
> my $inputFile = 'hostlist3.txt';
>
> open my $HOSTLIST, '<', $inputFile
> or die "can't open hostlist: $!";
>
> $/ = ''; # this will read a paragraph at a time
> $\ = "\n"; # avoids needing to print it all the time
>
> while (<$HOSTLIST>) {
> my @hostList = split /\n/;
>
> my $adminHost = shift( @hostList ); # first line
>
> print 'adminHost=' . $adminHost;
>
> my $otherHosts = join ' ', map "ssh $_ uname -a", @hostList;
That doesn't look right.
> my $cmd = "ssh ccn\@$adminHost $otherHosts";
>
> print "executing '$cmd'";
> print `$cmd`;
> }
>
> The problem is that I can't seem to run more than one command from
> ssh.
> I don't really want to open and ssh connection for each otherHosts.
>
> What if hostlist3.txt is:
> host1.domain
> host2
> host3
>
> host4.domain
> ...
>
> I need 'ssh host1.domain ssh host2 uname -a ssh host3 uname -a'.
No, you don't.
ssh host2 uname -a ssh host3 uname -a
is not the command you want to execute on host1.domain. Maybe you want
to execute
ssh host2 uname -a; ssh host3 uname -a
hp