For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > March 2008 > Re: ssh ssh









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: ssh ssh
Peter J. Holzer

2008-03-31, 8:42 am

On 2008-03-27 18:47, jammer <jameslockie@mail.com> wrote:
> 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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com