E
erik
I tried to find the answer on the web, camel book, and did not know
which perldoc to look in(perlop did not have it). I also tried a few
different things to make it work, any nothing has worked.
I dynamically create an array from an expect output. I want to then
print it out in a different array. I research references private vs.
global scalars and did not find my answer. This is my code:
#!/usr/bin/perl
#################################################################
# Global Variables #
#################################################################
use warnings;
use Expect;
use CGI(":standard");
$Expect::Log_Stdout = 0;
$device = param("device");
$username = param("username");
$password = param("password");
$enable = "enable";
$save = "wr mem";
$enable_password = param("enable_password");
$service_type = param("service_type");
my $datetemp = `date +%x_%r`;
my @dateStamp = split('\n',$datetemp);
my @bandwidth_array;
my $bandwidth_array;
(SNIP)
##################################################################
# Now we check for bandwidth statement #
###################################################################
sub bandwidth_router_check{
$timeout ="15";
my $bandwidth = "The router has at least 1 bandwidth statement";
my $no_bandwidth = "The router is missing a bandwidth statement";
$command->clear_accum();
print $command "show config \| inc band\r";
unless ($command->expect($timeout, -re, '#')) {
return "Never got telnet prompt".$command->exp_error()."\n";
}
my $bandwidth_capture = $command->exp_before();
my @bandwidth_array = split ('\n', $bandwidth_capture);
#HERE WE CHECK LOGGING
if ($bandwidth_capture =~ /band.*/)
{
push (@band_tests, $bandwidth);
$band_action = "OK";
}
else{
push (@band_tests, $no_bandwidth);
$band_action = "FAIL";
}
print "bandwidth_array 1 is $bandwidth_array[1]\n"; #THIS PRINT WORKS
GREAT!
};#end sub
Then I call it in a different sub-routine.
################################################################### #
Prints the main parameters that should be in ALL routers #
###################################################################
sub print_main_report
{
my @bandwidth_array;
my $bandwidth_array;
print "Content-type: text/html\n\n";
print "<html><head><title>QA REPORT</title></head>";
print "<body bgcolor=#000000>";
print "<p align=center><b><font color=#FFFFFF size=5>ROUTER QA
REPORT</font></b></p>";
print "<br>";
print "<p align=center><font color=#FFFFFF><b>Date: $dateStamp[0]
EST<b></font></p>";
print "<br>";
print "<body><font color=#FFFFFF><b>QA Report for:
$device<b></font></body>";
print "<br>";
print "<br>";
#we print for bandwidth
if ($band_action eq "OK")
{
print "<body><font
color=33CC33>@band_tests.............$band_action</font></body>";
}
else{
print "<body><font
color=FF0000>@band_tests.............$band_action</font></body>";
}
print "<br>";
print "<body>bandwidth_array 1 is $bandwidth_array[1]</body>";
#THIS DOES NOT PRINT AN ELEMENT, IT PRINT AN EMPTY ELEMENT.
print "<br>";
}
Can anyone give me some input? I tried to may the refences to it global
instead of scoped, but that did not do it. How should this sort of
thing be done?
which perldoc to look in(perlop did not have it). I also tried a few
different things to make it work, any nothing has worked.
I dynamically create an array from an expect output. I want to then
print it out in a different array. I research references private vs.
global scalars and did not find my answer. This is my code:
#!/usr/bin/perl
#################################################################
# Global Variables #
#################################################################
use warnings;
use Expect;
use CGI(":standard");
$Expect::Log_Stdout = 0;
$device = param("device");
$username = param("username");
$password = param("password");
$enable = "enable";
$save = "wr mem";
$enable_password = param("enable_password");
$service_type = param("service_type");
my $datetemp = `date +%x_%r`;
my @dateStamp = split('\n',$datetemp);
my @bandwidth_array;
my $bandwidth_array;
(SNIP)
##################################################################
# Now we check for bandwidth statement #
###################################################################
sub bandwidth_router_check{
$timeout ="15";
my $bandwidth = "The router has at least 1 bandwidth statement";
my $no_bandwidth = "The router is missing a bandwidth statement";
$command->clear_accum();
print $command "show config \| inc band\r";
unless ($command->expect($timeout, -re, '#')) {
return "Never got telnet prompt".$command->exp_error()."\n";
}
my $bandwidth_capture = $command->exp_before();
my @bandwidth_array = split ('\n', $bandwidth_capture);
#HERE WE CHECK LOGGING
if ($bandwidth_capture =~ /band.*/)
{
push (@band_tests, $bandwidth);
$band_action = "OK";
}
else{
push (@band_tests, $no_bandwidth);
$band_action = "FAIL";
}
print "bandwidth_array 1 is $bandwidth_array[1]\n"; #THIS PRINT WORKS
GREAT!
};#end sub
Then I call it in a different sub-routine.
################################################################### #
Prints the main parameters that should be in ALL routers #
###################################################################
sub print_main_report
{
my @bandwidth_array;
my $bandwidth_array;
print "Content-type: text/html\n\n";
print "<html><head><title>QA REPORT</title></head>";
print "<body bgcolor=#000000>";
print "<p align=center><b><font color=#FFFFFF size=5>ROUTER QA
REPORT</font></b></p>";
print "<br>";
print "<p align=center><font color=#FFFFFF><b>Date: $dateStamp[0]
EST<b></font></p>";
print "<br>";
print "<body><font color=#FFFFFF><b>QA Report for:
$device<b></font></body>";
print "<br>";
print "<br>";
#we print for bandwidth
if ($band_action eq "OK")
{
print "<body><font
color=33CC33>@band_tests.............$band_action</font></body>";
}
else{
print "<body><font
color=FF0000>@band_tests.............$band_action</font></body>";
}
print "<br>";
print "<body>bandwidth_array 1 is $bandwidth_array[1]</body>";
#THIS DOES NOT PRINT AN ELEMENT, IT PRINT AN EMPTY ELEMENT.
print "<br>";
}
Can anyone give me some input? I tried to may the refences to it global
instead of scoped, but that did not do it. How should this sort of
thing be done?