perl output

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ravimath
    New Member
    • Sep 2009
    • 14

    perl output

    Hi all ,

    I have written script to view some router output , my script executes successfuly , but does'nt show any output, why ?, it always shows output as 1.
    Code:
    use Net::Telnet;
    use Term::ReadKey;
    print "Enter username\n";
    $user = <STDIN>;
    chomp($user);
    ReadMode( "noecho", STDIN );
    print "Enter password\n";
    $pwd = <STDIN>;
    chomp($pwd);
    ReadMode ("original", STDIN) ;
     $epwd='pass';
    $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die');
    $telnet->open('x.x.x.x');
    $telnet->waitfor('/Username:/');
    $telnet->print($user);
    $telnet->waitfor('/Password:/');
    $telnet->print($pwd);
    
    sleep(1);
    $telnet->print('en');
    $telnet->waitfor('/Password:/');
    $telnet->print($epwd);
    
    sleep(1);
     @lines=$telnet->print('sh ver | inc System serial');
    sleep(1);
    print @lines;
    
    $telnet->close;
    please suggest some solution
  • chorny
    Recognized Expert New Member
    • Jan 2008
    • 80

    #2
    From documentation:

    $ok = $obj->print(@list) ;

    This method writes @list followed by the output_record_s eparator to the open object and returns 1 if all data was successfully written.


    P.S. Also you can try "dump_log" method.

    Comment

    • ravimath
      New Member
      • Sep 2009
      • 14

      #3
      can you suggest changes in above program to get output insted of output 1

      Comment

      • chorny
        Recognized Expert New Member
        • Jan 2008
        • 80

        #4
        Use "cmd" method instead of "print".

        Comment

        • ravimath
          New Member
          • Sep 2009
          • 14

          #5
          I have tried "cmd" method instead of "print". but no change , it still gives output as 1 please help

          Comment

          • RonB
            Recognized Expert Contributor
            • Jun 2009
            • 589

            #6
            Try this version and then check the 2 log files.
            Code:
            #!/usr/bin/perl
            
            use strict;
            use warnings;
            use Net::Telnet;
            use Term::ReadKey;
            
            print "Enter username\n";
            chomp(my $user = <STDIN>);
            
            ReadMode 'noecho';
            print "Enter password\n";
            chomp(my $pwd = <STDIN>);
            ReadMode 'normal';
            
            my $epwd = 'pass';
            
            my $telnet = Net::Telnet->new(
                                          Input_log => 'inputlog',
                                          Dump_log  => 'dumplog'
                                         );
            
            $telnet->open('x.x.x.x');
            $telnet->waitfor('/Username:/');
            $telnet->print($user);
            $telnet->waitfor('/Password:/');
            $telnet->print($pwd);
             
            sleep(1);
            $telnet->print('en');
            $telnet->waitfor('/Password:/');
            $telnet->print($epwd);
             
            sleep(1);
            my @lines = $telnet->cmd('sh ver | inc System serial');
            sleep(1);
            print @lines;
             
            $telnet->close;

            Comment

            • ravimath
              New Member
              • Sep 2009
              • 14

              #7
              I have tried above version , it gives error at line 35 and shows command_timeout at line 35 and not printing any output on monitor ,
              but when i checked inputlog it shows proper output which includes username , password , banner and required output of router . i want only the result of line 35 in that file . please suggest changes

              Comment

              • chorny
                Recognized Expert New Member
                • Jan 2008
                • 80

                #8
                How long is 'sh ver | inc System serial' executed before returning to command prompt, if run directly?

                ->cmd method may receive some lines, but it waits for command to finish.

                Comment

                • RonB
                  Recognized Expert Contributor
                  • Jun 2009
                  • 589

                  #9
                  What is the exact wording of the error?

                  What router (brand and model) are you connecting to?

                  What is the expected output of your command supposed to be?

                  Are you sure your router's cli supports (what appears to be) a piped command?

                  Comment

                  • ravimath
                    New Member
                    • Sep 2009
                    • 14

                    #10
                    Hi,
                    it takes just 2 seconds before returning to command prompt ,
                    i am connecting to cisco 1841 router ant it supports a piped command

                    Comment

                    Working...