Hi pals,

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);

the second screen:

#!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


I am facing problems in retrieving the session in teh second screen and not able to configure.
Can anyone help me..
Thanks in advance, mnsbb

janitored by ybiC: Balanced <code> and <readmore> tags


In reply to regarding session in CGI by mnsbb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.