WaltSteadman
MIS
I am trying to use a Perl Script to log in to a Netscreen Firewall. Since the Firewall requires interactive mode only, I need to use an Expect script or Net::SSH:Expect I think. I have no idea how to feed the expect script information into the perl script. Have looked on alot of sites that explain expect and have hit brick walls. The expect script is at the bottom of the script below. I want to log in to the device and run a command then log into the next device and run the same command and have the perl script display the results. The script runs but never does anything with the expect portion and I am assuming it is because I have used the wrong syntax or just scripted in wrong entirely. I would greatly appreciate any assistance. Thanks in Advance
Wally Steadman
SCRIPT BELOW:
++++++++++++++++++++++++++++++++++++++++++++++++++++
#!/usr/bin/perl -w
require "cgi-lib.pl";
use Date::Calc qw
all);
use Text::Wrap;
use CGI:
retty qw/:standard :cgi-lib/;
use Getopt::Long;
use CGI::Carp qw(fatalsToBrowser);
use expect;
@fwlog='firewall1a,firewall1b';
&ReadParse(*input);
print header();
print start_html(-title=>'Firewall BGP Checks',
-author=>'me@my.com',
-style=>{'src'=>'/netcheck/css/default.css'},
-id=>'form',
);
print end_html;
print "<pre>";
$username=$input{'username'};
$password=$input{'password'};
$firewall=$input{'firewall'};
GetOptions(
"username=s" =>\$username,
"password=s" => \$password,
"firewall=s" => \$firewall,
);
@fwlog = split(/,/,$fwlog);
if ($firewall =~ m/myloc10myslot15/)
{
$fwid = "65001";
print "$firewall \n";
print "ID IS $fwid \n";
}
elsif ($firewall =~ m/myloc13myslot31/)
{
$fwid = "65002";
print "$firewall \n";
print "ID IS $fwid \n";
}
elsif ($firewall =~ m/myloc10myslot32/)
{
$fwid = "65003";
print "$firewall \n";
print "ID IS $fwid \n";
}
elsif ($firewall =~ m/myloc5myslot7/)
{
$fwid = "65004";
print "$firewall \n";
print "ID IS $fwid \n";
}
elsif ($firewall =~ m/myloc13myslot26/)
{
$fwid = "65005";
print "$firewall \n";
print "ID IS $fwid \n";
}
elsif ($firewall =~ m/myloc13myslot26/)
{
$fwid = "65006";
print "$firewall \n";
print "ID IS $fwid \n";
}
else
{
print "Firewall not listed";
}
### THIS IS THE PART I AM LOST ON ###
foreach $fwlog (@fwlog)
{
my $ssh = Net::SSH::Expect->new (
host => "$firewall",
password=> '$password',
user => '$username',
raw_pty => 1);
$ssh->run_ssh() or die "SSH process couldn't start: $!";
($ssh->read_all(2) =~ />\s*\z/) or die "where's the remote prompt?"
my $command = $ssh->exec("get vr CC-vr protocol bgp rib-in | include $fwid");
print ($command);
}
++++++++++++++++++++++++++++++++++++++++
SCRIPT END
Wally Steadman
SCRIPT BELOW:
++++++++++++++++++++++++++++++++++++++++++++++++++++
#!/usr/bin/perl -w
require "cgi-lib.pl";
use Date::Calc qw
use Text::Wrap;
use CGI:
use Getopt::Long;
use CGI::Carp qw(fatalsToBrowser);
use expect;
@fwlog='firewall1a,firewall1b';
&ReadParse(*input);
print header();
print start_html(-title=>'Firewall BGP Checks',
-author=>'me@my.com',
-style=>{'src'=>'/netcheck/css/default.css'},
-id=>'form',
);
print end_html;
print "<pre>";
$username=$input{'username'};
$password=$input{'password'};
$firewall=$input{'firewall'};
GetOptions(
"username=s" =>\$username,
"password=s" => \$password,
"firewall=s" => \$firewall,
);
@fwlog = split(/,/,$fwlog);
if ($firewall =~ m/myloc10myslot15/)
{
$fwid = "65001";
print "$firewall \n";
print "ID IS $fwid \n";
}
elsif ($firewall =~ m/myloc13myslot31/)
{
$fwid = "65002";
print "$firewall \n";
print "ID IS $fwid \n";
}
elsif ($firewall =~ m/myloc10myslot32/)
{
$fwid = "65003";
print "$firewall \n";
print "ID IS $fwid \n";
}
elsif ($firewall =~ m/myloc5myslot7/)
{
$fwid = "65004";
print "$firewall \n";
print "ID IS $fwid \n";
}
elsif ($firewall =~ m/myloc13myslot26/)
{
$fwid = "65005";
print "$firewall \n";
print "ID IS $fwid \n";
}
elsif ($firewall =~ m/myloc13myslot26/)
{
$fwid = "65006";
print "$firewall \n";
print "ID IS $fwid \n";
}
else
{
print "Firewall not listed";
}
### THIS IS THE PART I AM LOST ON ###
foreach $fwlog (@fwlog)
{
my $ssh = Net::SSH::Expect->new (
host => "$firewall",
password=> '$password',
user => '$username',
raw_pty => 1);
$ssh->run_ssh() or die "SSH process couldn't start: $!";
($ssh->read_all(2) =~ />\s*\z/) or die "where's the remote prompt?"
my $command = $ssh->exec("get vr CC-vr protocol bgp rib-in | include $fwid");
print ($command);
}
++++++++++++++++++++++++++++++++++++++++
SCRIPT END