Telnet - How to not displayed something on web page

L

Lalo

Hi,

I am using Expect wrapper in perl telnet to machine and do ls -ltra
on remote machine

Everything work fine and I can see the following on my web page :

******************************************************************************
You have chosen : abc.


Your var is : abc:

Telnet AA.BB.CC.DD 2100:



cd /tmp ls -ltra > log2.log ^] Trying AA.BB.CC.DD 2100... Connected to
AA.BB.CC.DD 2100. Escape character is '^]'. telnet> quit Connection
closed.
*********************************************************************



The "problem" is I don't want that portion "cd /tmp ls -ltra >
log2.log ^]" is displayed on web page, I would like that that part be
skipped and not dispayed somehow.

I thought that command Print_start print_end will handle that, but
obviously not.
Below is source code.

Thanks in advance for any help/suggestions.



***************************************************************************
#!/usr/bin/perl -w
use Expect;

use CGI qw:)standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use strict;

print header;

my $exp = new Expect;



my $var = param('VAR');
print "You have chosen : $var.<br><br>\n";
print start_html;
if ($var eq "abc") {
print "\n<br>Your var is : $var: <br>\n";
print "\n<br> Telnet AA.BB.CC.DD 2100: <br><br>\n";
my $exp = new Expect;
my $command = 'telnet AA.BB.CC.DD 2100';
$exp->spawn($command) or die "Cannot spawn $command: $!\n";
print "<br>";
print end_html;

print "<br>\n";

$exp->send("cd /tmp\n");
$exp->send("ls -ltra > log2.log\n");


print start_html;
$exp->send("\x1d\n");
my $tel = $exp->expect(30, 'telnet>');
$exp->send("quit\r");
print end_html;
$exp->interact();
}

elsif ($var eq "def") {


}
 
T

Ted Zlatanov

L> I am using Expect wrapper in perl telnet to machine and do ls -ltra
L> on remote machine

Have you tried Net::Telnet? It makes the task much, much easier than
the way you're doing it.

L> my $var = param('VAR');
L> print "You have chosen : $var.<br><br>\n";
L> print start_html;
L> if ($var eq "abc") {
L> print "\n<br>Your var is : $var: <br>\n";
L> print "\n<br> Telnet AA.BB.CC.DD 2100: <br><br>\n";
L> my $exp = new Expect;
L> my $command = 'telnet AA.BB.CC.DD 2100';
L> $exp->spawn($command) or die "Cannot spawn $command: $!\n";
L> print "<br>";
L> print end_html;

L> print "<br>\n";

L> $exp->send("cd /tmp\n");
L> $exp->send("ls -ltra > log2.log\n");


L> print start_html;
L> $exp->send("\x1d\n");
L> my $tel = $exp->expect(30, 'telnet>');
L> $exp->send("quit\r");
L> print end_html;
L> $exp->interact();
L> }

L> elsif ($var eq "def") {


L> }

Look at the Template module (AKA Template Toolkit), it will make the
above much easier by letting you write a simple web page template you
can fill in with your data. It supports IF-THEN and FOREACH constructs.

I'd suggest doing the work first (in an eval if possible), then
generating the HTML. Otherwise a problem in the telnet session code
will break your page.

Ted
 
L

Lalo

L> I am using Expect wrapper in perl telnet to machine and do ls -ltra
L> on remote machine

Have you tried Net::Telnet? It makes the task much, much easier than
the way you're doing it.

L> my $var = param('VAR');
L> print "You have chosen : $var.<br><br>\n";
L> print start_html;
L> if ($var eq "abc") {
L> print "\n<br>Your var is : $var: <br>\n";
L> print "\n<br> Telnet AA.BB.CC.DD 2100: <br><br>\n";
L> my $exp = new Expect;
L> my $command = 'telnet AA.BB.CC.DD 2100';
L> $exp->spawn($command) or die "Cannot spawn $command: $!\n";
L> print "<br>";
L> print end_html;

L> print "<br>\n";

L> $exp->send("cd /tmp\n");
L> $exp->send("ls -ltra > log2.log\n");

L> print start_html;
L> $exp->send("\x1d\n");
L> my $tel = $exp->expect(30, 'telnet>');
L> $exp->send("quit\r");
L> print end_html;
L> $exp->interact();
L> }

L> elsif ($var eq "def") {

L> }

Look at the Template module (AKA Template Toolkit), it will make the
above much easier by letting you write a simple web page template you
can fill in with your data. It supports IF-THEN and FOREACH constructs.

I'd suggest doing the work first (in an eval if possible), then
generating the HTML. Otherwise a problem in the telnet session code
will break your page.

Ted

Thank you Ted.

I'll take a look at.
To be honest, I haven't looked into it.

Thanks again,
Lalo
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top