1

I am new to Perl and HTML . I have written a back end script in Perl using send expect statements, for loops and subroutines. In the Perl script i am logging in to the server and sending some commands and expecting server prompt and finally exit .Now i am trying to bring it to front end using HTML. I am using CGI as a framework to achieve this. This is my part of the code

#!/usr/bin/perl

use Expect;
use Switch;
use warnings;
use 5.008;
use Data::Dumper;
use CGI;

my $q = CGI->new;

my %data;
$data = $q->param('server');
print $q->header;


if($data eq 'null')
{
    print '<p> please select a server</p>';
    exit;

}


### 


    $exp->spawn($command, @parameters)
        or die "Cannot spawn $command: $!\n";

      $exp->send("string\n");


      $exp->expect($timeout, @match_patterns);


      $exp->expect($timeout,
               [ qr/regex1/ => sub { my $exp = shift;
                         $exp->send("response\n");
                         exp_continue; } ],
               [ "regexp2" , \&callback, @cbparms ],
              );


      $exp->soft_close();

these are the examples of send expect commands iam using to logging in to server and sending commands. but i am seeing them in the browser how they ll login . but i dont want these to be seen on browser but they should still execute in background

####

print "<html><head><title>Hello World</title></head>\n";
print "<body>\n";
print '<script>checked = false;function checkedAll () {if (checked == false){checked = true}else{checked = false}for (var i = 0; i < document.getElementById("sel").elements.length; i++) {document.getElementById("sel").elements[i].checked = checked;}}</script>';
print '<form action="robostats.pl " method="POST" id="sel">';
print '<input type="checkbox" onClick="checkedAll()">Select All<br />';

foreach my $i (@entire_success) {
    print '<input type="checkbox" name="sel" value="';
    print $i;
    print '">';
    print $i;
    print '<br />';
}

print '<input type="submit" value="submit">';
print '</form>';
print "</body></html>\n";

so when i am trying to run in the browser those send expect commands, server login prompts are all coming on the browser . I dont want them to be on the browser(they should only come in the console), I only want to capture its output in an array and display the checkboxes of the form on the browser. Please help me o how to achieve this. Thank you

13
  • Have you tried log_user 0 in the expect script? It turns off logging of commands and results. Commented Mar 7, 2014 at 9:29
  • By the way, your script is kind of littered with print statements, you might consider using "here" documents to improve clarity and performance, e.g. print<<EOF<html><head>..... EOF Commented Mar 7, 2014 at 9:39
  • no i havent tried . I dont know how to use it . Should i include before use Expect statements??? @MarkSetchell Commented Mar 7, 2014 at 9:49
  • @MarkSetchell i just used it but it is giving internal server error , if i remove log_user 0 . i am seeing all my login details and prompts where the commands go. Pls help me Commented Mar 7, 2014 at 9:59
  • It should be the first Expect command. Commented Mar 7, 2014 at 10:03

1 Answer 1

1

You probably need to turn off logging/echoing of commands at the start of your Expect script, like this:

$exp->log_user(0);
Sign up to request clarification or add additional context in comments.

5 Comments

I want to log what is happening and store it in a file . Is this possible here ?
Try this $exp->log_file("$host.log");
where will it be saved?
I think it comes out in "real time" - you may have to try changing the other line to $exp->log_user(1) to re-enable messages since it turned them off for you before.
I want $exp->log_user(0) to diable messages , but still want a log to be created :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.