telnet from perl


S

siddhartha mulpuru

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
 
Ad

Advertisements

J

John Bokma

(e-mail address removed) (siddhartha mulpuru) wrote in
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?....
 
Ad

Advertisements

B

Brian McCauley

siddhartha said:
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."
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top