Telnet - How to not displayed something on web page

Discussion in 'Perl Misc' started by Lalo, Nov 4, 2008.

  1. Lalo

    Lalo Guest

    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") {


    }
    Lalo, Nov 4, 2008
    #1
    1. Advertising

  2. Lalo

    Ted Zlatanov Guest

    On Tue, 4 Nov 2008 13:54:37 -0800 (PST) Lalo <> wrote:

    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
    Ted Zlatanov, Nov 4, 2008
    #2
    1. Advertising

  3. Lalo

    Lalo Guest

    On Nov 4, 6:13 pm, Ted Zlatanov <> wrote:
    > On Tue, 4 Nov 2008 13:54:37 -0800 (PST) Lalo <> wrote:
    >
    > 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
    Lalo, Nov 5, 2008
    #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. boney
    Replies:
    1
    Views:
    542
  2. Jim Isaacson
    Replies:
    5
    Views:
    592
    Default User
    Nov 5, 2004
  3. Jayesh Suthar

    some controls not displayed on web page

    Jayesh Suthar, Oct 11, 2003, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    89
    Kris Childs
    Oct 16, 2003
  4. mithu
    Replies:
    6
    Views:
    120
    mithu
    Dec 13, 2004
  5. Carcarius
    Replies:
    0
    Views:
    270
    Carcarius
    Dec 6, 2007
Loading...

Share This Page