getting output of telnet from perl script

Ask a Question related to PERL Modules, Design and Development.

  1. #1

    Default getting output of telnet from perl script

    hi all,
    i had written a code to connect to unix server from Windows xp where i
    installed perl.
    i have to do with telnet. I think I am able to connect with unix
    server. but i am not able to get out put from the server. i have tried
    with 'ls' and 'who' commands. it is giving output
    "connectedlogged inBefore ls".

    The code is :
    use Net::Telnet;


    # instantiate a new CGI object
    my $telnet = new Net::Telnet(Timeout => 10,
    Errmode => 'die');


    $telnet->open("servername") or die "hai $telnet->errmsg ";
    print "connected";
    $telnet->waitfor('/login: $/i');
    $telnet->print("ixlourd") or die $telnet->errmsg;
    $telnet->waitfor('/password: $/i');
    $telnet->print("qwest1") or die $telnet->errmsg;
    print "logged in";
    $telnet->waitfor('/ixlourd\@e2epia2: $/');
    print "Before ls";
    $telnet->print('who');
    $telnet->waitfor('/ixlourd\@e2epia2: $/');
    #$output = $telnet->waitfor('/\$ $/i');
    print $output;
    @lines=$telnet->print("ls") or die $telnet->errmsg;


    print @lines;


    OUTPUT:
    "connectedlogged inBefore ls".


    I have copied telnet.pm module from CPAN to perl directory. why it is
    not giving any output of 'ls' . it is simply it is giving
    "connectedlogged inBefore ls"
    How can i make check whether it is connected to my unix server
    successfully.

    kishore.konjeti@gmail.com Guest

  2. Similar Questions and Discussions

    1. getting output of telnet from perl
      hi i had written code to connect to unix server from Windows xp(telnet) where i installed perl. i have to do with telnet. I think I am able to...
    2. Net::Telnet not working with perl 5.8.5
      Hi, I am working on a test framework which uses "Net::Telnet" module to connect to remote machines. This framework started failing after I...
    3. Telnet from perl
      I use this NET::TELNET module to login into a telnet session.. THis is the code #!/usr/bin/perl use CGI; $frm = new CGI; $unix_box =...
    4. Telnet - How to put delays on output?
      Hi! I have a slow device attached to a terminal server reachable by socket. To access it just do "telnet ip-address socket-number". I need to...
    5. Perl and telnet
      Hello, I am trying to get Perl to make the hard things possible, but I'm having my doubts on this one... We basically have a huge C program...
  3. #2

    Default Re: getting output of telnet from perl script


    Don't have Net::Telnet here, but does it not have a debug option.

    Debug=>Filename ??

    Check perldoc Net::Telnet


    Owen

    xemoth@gmail.com Guest

  4. #3

    Default Re: getting output of telnet from perl script

    yes i am getting output of telnet in debug folder by specifiying in
    input_log parameter while telnet object construction. It is showing
    correctly.. but i am not able to print using print @lines.
    the code is i have written like this
    use warnings;
    use Net::Telnet;
    my $dumplog = "dumplog.txt";
    my $outputlog = "outputlog.txt";
    my $inputlog="inputlog.txt";
    # instantiate a new CGI object
    my $telnet = new Net::Telnet(Timeout => 10,
    Errmode => 'die',
    Dump_Log => "$dumplog",
    output_log => "$outputlog",
    input_log=>"$inputlog",

    );
    # perform a single print statement, with liberal use of the perl
    # string concatenator "." and some CGI methods

    $telnet->open("server");
    $telnet->waitfor('/login: $/i');
    #$telnet->output_record_separator("\n");
    $telnet->print("ixlourd") ;
    $telnet->waitfor('/password: $/i');
    $telnet->print("qwest1") ;

    $telnet->waitfor('/ixlourd\@e2epia2: $/') ;


    print "Before ls\n";


    @lines= $telnet->cmd("banner KISHORE");
    sleep(5);

    print @lines; # here i am getting timed out error.

    kishore.konjeti@gmail.com Guest

  5. #4

    Default Re: getting output of telnet from perl script


    [email]kishore.konjeti@gmail.com[/email] wrote:
    > yes i am getting output of telnet in debug folder by specifiying in
    > input_log parameter while telnet object construction. It is showing
    > correctly.. but i am not able to print using print @lines.
    > the code is i have written like this
    > use warnings;
    > use Net::Telnet;
    > my $dumplog = "dumplog.txt";
    > my $outputlog = "outputlog.txt";
    > my $inputlog="inputlog.txt";
    > # instantiate a new CGI object
    > my $telnet = new Net::Telnet(Timeout => 10,
    > Errmode => 'die',
    > Dump_Log => "$dumplog",
    > output_log => "$outputlog",
    > input_log=>"$inputlog",
    >
    > );
    > # perform a single print statement, with liberal use of the perl
    > # string concatenator "." and some CGI methods
    >
    > $telnet->open("server");
    > $telnet->waitfor('/login: $/i');
    > #$telnet->output_record_separator("\n");
    > $telnet->print("ixlourd") ;
    > $telnet->waitfor('/password: $/i');
    > $telnet->print("qwest1") ;
    >
    > $telnet->waitfor('/ixlourd\@e2epia2: $/') ;
    >
    >
    > print "Before ls\n";
    >
    >
    > @lines= $telnet->cmd("banner KISHORE");
    > sleep(5);
    >
    > print @lines; # here i am getting timed out error.
    How can you be trying to use a module without reading the
    documentation?

    if you prompt is really 'ixlourd@e2epia2: ' then the default Prompt
    won't work ((care of the documentation I know that The default Prompt
    is '/[\$%#>] $/')), so how do you expect cmd() to know when it's done
    getting input?? It sits there waiting to see something it recognizes
    until it times out.

    Here's how I usually approach this kind of problem:
    1) read module documentation
    2) write script with frequent reference to module documentation and
    examples therein
    3) run script
    4) when (not if) script does not do what I expected, re-read
    documentation and debug

    You may want to consider a similar approach.

    -jp

    DJ Stunks Guest

  6. #5

    Default Re: getting output of telnet from perl script

    I have red the document. can u briefly tell this.. that means.. wht r
    the changes i have to do in my script..( waitfor is for waiting for a
    specified text needs to appear then can i use sleep for a time. may for
    2 or 3 sec..) ..insted of cmd will print command can i use for
    executing any commands and getting output of it in a variable ... how
    can i supress timed out warning..
    -kish

    kishore.konjeti@gmail.com Guest

  7. #6

    Default Re: getting output of telnet from perl script

    [email]kishore.konjeti@gmail.com[/email] wrote:
    > I have red the document.
    What document? Documentation to some module? Which module are your talking
    about?
    > can u briefly tell this.. that means.. wht
    What do you mean by "u"? I realize that English is not your native language,
    but please make an effort to write readable text.
    > r the changes i have to do in my script..
    What do you mean by "r"? I realize that English is not your native language,
    but please make an effort to write readable text.

    What script? I don't see any script in your posting.
    > ( waitfor is for waiting for
    > a specified text needs to appear then can i use sleep for a time.
    Are you asking a question or are you making a statement here? I really don't
    understand.
    > may
    > for 2 or 3 sec..)
    You know, newlines are not a scarce resource. Hitting the "enter" key every
    now and then in the right places would improve the readability of your text
    significantly. And I assume you want to be read, right?
    > ..insted of cmd will print command can i use for
    What the *$#%&$% ? What is that supposed to mean? "Instead of cmd will print
    command can I use".
    Sorry, my English parser fails to parse that sentence.
    > executing any commands and getting output of it in a variable .
    Are you looking for backticks by any chance? See also the documentation of
    system().
    > .. how
    > can i supress timed out warning..
    Perl does not generate timeout warnings. Check the documentation of whatever
    tools happens to generate them.

    jue


    Jürgen Exner Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139