mnsbb has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to telnet to a machine and perform some operations. The idea is get some inputs from the user in the first screen and configure the machine with those inputs through the second one.
If i telnet to machine in the second screen it is taking 12 seconds time. i was told that i shall use CGI session, so that i can telnet to the machine inthe first screen itself and store the telnet to a session; pass the session to the second screen and retrieve there.
I am struck with storing and retrieving the session.
here is the code first screen:#!e:/perl/bin/perl use CGI; use CGI::Session; require "telnet.pm"; print "Content-type:text/html\n\n"; print << "END_OF_MESSAGE"; <HTML><HEAD><TITLE>AutoGenerate</TITLE> <base target="_top"> </base> </HEAD> some stuff to collect inputs </HTML> END_OF_MESSAGE #create cgi object $cgi=new CGI; $session = new CGI::Session( "driver:File", $cgi, {Directory=>"C:/temp +/"} ); #create telnet object, and save it in session my $telnet = new Net::Telnet ( Timeout=>1, Errmode=>'return'); $telnet->open(Host=>'hostname', Port=>'port') or die "cannot login"; print "\nLogged: $telnet\n"; $teln = $cgi->param("$telnet"); $session->param($telnet, $teln);
#!e:/perl/bin/perl use CGI::Session; use CGI; print "Content-type:text/html\n\n"; $session = new CGI::Session( "driver:File", $cgi, {Directory=>"C:/temp +/"} ); $telnet = $session->param("$teln"); print "\nretrieved from session: $telnet"; $q = new CGI; if ($telnet) { $telnet->print("configure term\n"); $telnet->waitfor('/configure/i'); $telnet->print("exit\n"); $telnet->waitfor('/[\$%#:>].$/i'); $telnet->print("exit\n"); $telnet->waitfor('/[\$%#:>].$/i'); } else { print "Else of telnet: $telnet"; } print <<"EOM"; <HTML> </HTML> EOM
janitored by ybiC: Balanced <code> and <readmore> tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regarding session in CGI
by hanenkamp (Pilgrim) on Dec 17, 2003 at 14:41 UTC | |
by mnsbb (Initiate) on Dec 17, 2003 at 15:52 UTC | |
by hanenkamp (Pilgrim) on Dec 17, 2003 at 16:11 UTC | |
by mnsbb (Initiate) on Dec 22, 2003 at 04:47 UTC | |
by mnsbb (Initiate) on Dec 22, 2003 at 06:40 UTC | |
by barrd (Canon) on Dec 17, 2003 at 16:10 UTC |