telnet from perl

Discussion in 'Perl Misc' started by siddhartha mulpuru, Sep 24, 2004.

  1. 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 = $frm->param('unix_box');

    $username = $frm->param('username');

    $password = $frm->param('password');

    #$unix_box = "xxxx.xxx.xxx";

    #$username = "xxxxxx";

    #$password = "xxxxxxxx";

    my $prmpt = '/[\w().-]*[\$#>:.]\s?(?:\(enable\))?\s*$/';
    $telnet = new Net::Telnet ( Timeout=>20, Prompt => $prmpt,
    "Dump_log" => "dump_log",
    Errmode=>'die');
    use Net::Telnet;
    $telnet->open($unix_box);
    $telnet->waitfor('/login:/i');
    $telnet->print($username);
    $telnet->waitfor('/Enter SecurID PASSCODE:/i');
    $telnet->print($password);
    $telnet->waitfor('/.+:\/.+\/.+>/i');
    @lines= $telnet->cmd("who");
    #print STDOUT @lines;

    print "Content-type: text/html\n\n";

    print "
    @lines
    ";


    $telnet->close;

    When i run this script from the command line it works fine. But when i
    run this as a post from a form with values for username,password and
    unix box it does not work.

    Please advise

    Thanks
    Sid
    siddhartha mulpuru, Sep 24, 2004
    #1
    1. Advertising

  2. siddhartha mulpuru

    John Bokma Guest

    (siddhartha mulpuru) wrote in
    news::

    > When i run this script from the command line it works fine. But when i
    > run this as a post from a form with values for username,password and
    > unix box it does not work.


    describe "does not work"

    Check the error_log of the webserver, anything there?

    the use Net::Telnet is at a weird place, put it higher.

    open - connect to port on remote host
    "On success 1 is returned. On time-out or other connection failures, the
    error mode action is performed. See errmode()."

    maybe some error trapping?....

    --
    John MexIT: http://johnbokma.com/mexit/
    personal page: http://johnbokma.com/
    Experienced programmer available: http://castleamber.com/
    Happy Customers: http://castleamber.com/testimonials.html
    John Bokma, Sep 24, 2004
    #2
    1. Advertising

  3. siddhartha mulpuru wrote:

    > When i run this script from the command line it works fine. But when i
    > run this as a post from a form with values for username,password and
    > unix box it does not work.


    "does not work" is a red flag phrase. Whenever you find yourself typing
    it you should immediately delete it and instead replace it with an
    explaination of excatly in what way and at what point does it fails.

    (You may have to add diagnostic prints to STDERR and/or look in error
    logs to determine this).

    You should never, ever, dream of hitting send on a question to Usenet
    where the total description you give of the failure you are experiencing
    reads "it does not work".

    See also FAQ: "My CGI script runs from the command line but not the
    browser."
    Brian McCauley, Sep 24, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shuttermutt

    Perl telnet proxy

    Shuttermutt, Sep 3, 2003, in forum: Perl
    Replies:
    0
    Views:
    2,648
    Shuttermutt
    Sep 3, 2003
  2. Vinay Gupta
    Replies:
    2
    Views:
    1,098
    Michael Schlenker
    Jul 27, 2004
  3. CJ
    Replies:
    0
    Views:
    1,813
  4. Jim Isaacson
    Replies:
    5
    Views:
    593
    Default User
    Nov 5, 2004
  5. Carcarius
    Replies:
    0
    Views:
    278
    Carcarius
    Dec 6, 2007
Loading...

Share This Page