Hi Rob,

 Thanks a lot for looking into this........i can't execute cat command on
the routing devices, I was trying "sh run" on two devices, the show run
command dumps the current configuration of the routing device......i tried
executing "sh run" on two devices, one of the device has less configuration
and other one has more configuration.....when i ran this script on the
device with less configuration, i got the full output, but when i run the
same script on device with more configuration, i got the stripped
output.........it looks like it is getting timed out..........is there a way
to increase the timeout? (i tried setting $ssh->poll(0), but it didn't
help)......an example would be really helpful.


Thanks,




On Thu, Mar 11, 2010 at 4:31 PM, Sisyphus <sisyph...@optusnet.com.au> wrote:

>
> ----- Original Message ----- From: "perl_haxor 123" <perl.ha...@gmail.com>
> To: "Sisyphus" <sisyph...@optusnet.com.au>
> Cc: <beginners@perl.org>
> Sent: Thursday, March 11, 2010 6:38 AM
> Subject: Re: stripped output from Net::SSH2
>
>
>
>  find the script below:
>>
>> #!/usr/bin/perl -w
>> use strict;
>>
>> use Term::ReadKey;
>> use Net::SSH2;
>>
>> use constant BUFLEN => 10_0000;
>>
>>
>> my $user = "user";
>>
>> print "Enter the the password: ";
>> ReadMode 'noecho';
>> my $pass = ReadLine 0;
>> print "\n";
>> chomp $pass;
>> ReadMode 'normal';
>>
>> open INPUT, "<", "input.txt";
>> open STDERR, ">", "Error.txt";
>>
>>
>> while(<INPUT>) {
>>
>>
>>   chomp $_;
>>
>> my $ssh2 = Net::SSH2->new();
>>
>> unless ($ssh2->connect("$_")) {
>>
>> print "unable to connect to Host: $_\n";
>> print STDERR "Unable to connect to $_: $!\n";
>> print STDERR
>>
>> "#############################################################################################\n\n";
>> next;
>>
>> }
>>
>> print "connecting to $_\n";
>>
>>
>> unless ($ssh2->auth_password("$user","$pass")) {
>>
>>
>>   print "Invalid Password\n";
>>   exit;
>> }
>>
>> my $chan = $ssh2->channel;
>> $chan->exec('sh run');
>>
>> my $buf;
>> my $read = $chan->read($buf, BUFLEN);
>> warn 'More than ', BUFLEN, ' characters in listing' if $read >= BUFLEN;
>> open OUTPUT, ">", "$_.txt";
>> print OUTPUT "HOST: $_\n\n";
>> print OUTPUT "$buf\n";
>> print OUTPUT "\n\n\n";
>> print OUTPUT
>>
>> "##################################################################################################\n\n";
>> close OUTPUT;
>> $chan->close();
>> }
>>
>
>
> I can't reproduce the problem.
>
> However, I have access to only one SSH2 server, so my "input.txt" simply
> contained 3 identical lines - namely "192.168.0.3" (which is the IP address
> of the machine running the server).
>
> Does your problem go away if *you* connect to the same server at each
> iteration ?
>
> For me "sh run" just produces a single line of output - namely "run: run:
> No such file or directory". Not very useful, so I changed the command to
> "cat pscrpt/hello.pl" which prints out a multiline file. If you change
> your command to "cat some_multiline_file", does your problem go away ?
>
> Finally because I was connecting to the same server each time, I had to
> modify the script to create separate files for each iteration of the while
> loop. First iteration writes to 192.168.0.30.txt, second iteration to
> 192.168.0.31.txt and the third iteration to 192.168.0.32.txt.
>
> For each of those 3 iterations, pscrpt/hello.pl is correctly reproduced.
> In order to get the same error as you, do I need to:
> a) cat a bigger file ? (hello.pl is only about 15 lines)
> b) run some command other than cat ?
> c) iterate through the loop more than 3 times ?
> d) connect to different servers each time ?
>
> Do you get the error for *every* server you connect to ?
> If it's just *some* servers that are giving the problem, is it the *same*
> servers each time ? And do each of those "same" servers produce the error
> *every* time you run the script ?
>
> Finally, which version of perl are you running ?
> I have version 5.10.1, and am using Net-SSH2-0.28 (built against
> libssh2-1.2.2).
>
> There's a ppm for that version of Net-SSH2-0.28 (also built against
> libssh2-1.2.2) for both perl-5.8 and perl-5.10 at the uwinnipeg repository.
> If you're using a different version of Net::SSH2, maybe give that uwinnipeg
> ppm a try and see if it makes any difference.
>
> Sorry for all of the questions - but if I can't reproduce the problem it's
> going to be difficult to provide any useful help.
>
> Admittedly, it's not your fault that I have only one SSH2 server to connect
> to, or that "sh run" doesn't produce multiline output on that server :-)
>
> Below my sig is the actual script I ran.
>
> Cheers,
> Rob
>
> ##############################
>
> #!/usr/bin/perl -w
> use strict;
>
> use Term::ReadKey;
> use Net::SSH2;
>
> use constant BUFLEN => 10_0000;
>
> print "Enter username: ";
> my $user = <STDIN>;
> chomp $user;
>
>
> print "Enter the the password: ";
> ReadMode 'noecho';
> my $pass = ReadLine 0;
> print "\n";
> chomp $pass;
> ReadMode 'normal';
>
> my $inc = 0; # Incremented at each iteration
>            # of the while loop
>
>
> open INPUT, "<", "input.txt";
> open STDERR, ">", "Error.txt";
>
>
> while(<INPUT>) {
>
>
>   chomp $_;
>
> my $ssh2 = Net::SSH2->new();
>
> unless ($ssh2->connect("$_")) {
>
> print "unable to connect to Host: $_\n";
> print STDERR "Unable to connect to $_: $!\n";
> print STDERR
>
> "#############################################################################################\n\n";
> next;
>
> }
>
> print "connecting to $_\n";
>
> unless ($ssh2->auth_password("$user","$pass")) {
>   print "Invalid Password\n";
>   exit;
> }
>
> my $chan = $ssh2->channel;
> #$chan->exec('sh run');
> $chan->exec('cat pscrpt/hello.pl');
>
>
> my $buf;
> my $read = $chan->read($buf, BUFLEN);
> warn 'More than ', BUFLEN, ' characters in listing' if $read >= BUFLEN;
> open OUTPUT, ">", "$_$inc.txt";
>
> print OUTPUT "HOST: $_\n\n";
> print OUTPUT "$buf\n";
> print OUTPUT "\n\n\n";
> print OUTPUT
>
> "##################################################################################################\n\n";
> close OUTPUT;
> $chan->close();
> $inc++;
> }
>
> ########################################
>

Reply via email to