2009/3/4 monnappa appaiah <monnapp...@gmail.com>:
> Hi all,
Hi

> Hi i'm able to connect to mulitple hosts now and it will login to all the
> hosts specified in the input file (input.txt)

>
> if there is a host which doesn't exist in input file (input.txt), the
> program ends without going to the next host in the file
>
>
>
> for example: if the input.txt has three hosts ( host1, host2 and host3),
> assuming that host2 doesn't exist.....then it will not login to host2 and
> execute the command and give the output.
>
>
> i also tried warn instead of die.............can somebody help me with this,
> i have pasted my code below
>

I would have thought that warn (and next) would have been exactly what
you want. You could try this

>
> #!/usr/bin/perl -w
> use strict;
> use warnings;
>
> use Net::SSH2;
>
> use constant BUFLEN => 10_000;
>
> open my $input, '<', 'input.txt' or die $!;
> open OUTPUT, '>', 'output.txt' or die $!;
>
> while (<$input>) {
> chomp;
> my $ssh2 = Net::SSH2->new;

       $ssh2->connect($_) or warn "Unable to connect host $_\n" and next;

>$ssh2->auth_password('<username>','<password>');
> my $chan = $ssh2->channel;
> $chan->exec('ls -al');
>
> my $buf;
> my $read = $chan->read($buf, BUFLEN);
> die 'More than ', BUFLEN, ' characters in listing' if $read >= BUFLEN;
> print OUTPUT "$buf\n";
> print OUTPUT "\n\n\n";
> print OUTPUT
> "----------------------------------------------------------------------------------------------------------------";
> $chan->exec('exit');
> $ssh2->disconnect;
>
>
> Thanks,
> Monnappa


Good luck,
Dp.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to