Hi all
I've written a Perl based expect "script" that utilises SSH to connect to a SBC and execute various commands that I want to capture in order to provide monitoring of the appliance.
Presently the only way I can acquire the output from the "Expect" script is to not use the Perl module "Expect", here is the working script:
#!/usr/bin/expect
set timeout 10
log_user 0
spawn ssh 1.1.1.1
expect "?*"
send "show sessions\r"
log_user 1
expect "?*"
send "exit\r"
This produces output that I can use but I want to use Perl to do this, here is my Perl script so far:
#!/usr/bin/perl -w
#
use strict;
use expect;
# Vars
our ($timeout,$output,$process);
$timeout = $output = $process = "";
# SSH vars
my $sshUsername = "user";
my $sshHostname = "1.1.1.1";
my $sshTimeout = 10;
my $sshCommand = "/usr/bin/ssh";
# SBC vars
my $sbcCommand = "show sessions";
my $sbcExitcmd = "exit";
# Diagnostic options
#$Expect::Exp_Internal = 1; # Turn on debugging
#$Expect::Log_Stdout = 0; # Turn off debugging
# Initialize expect based SSH session to remote host
my $exp = Expect->spawn($sshCommand, $sshHostname, $sshUsername);
# Lets ensure that we accept the initial key request if we have not lo
+gged in before
#$exp->expect($timeout,
# ["Are you sure you want to continue connecting", sub {
+my $self = shift; $self->send("yes\n");}]
# );
# Wait for SBC prompt
print "About to execute the command\n";
$exp->expect($timeout, ["."]);
# Send SBC command
$exp->send("$sbcCommand\n");
# Wait for subsequent prompt (any prompt, we just want the command out
+put)
$exp->expect($timeout, ["."]);
# Send exit command to quit the SBC shell
$exp->send("$sbcExitcmd\n");
# Capture output (THIS DOES NOT WORK, ONLY SHOWS COMMANDS EXECUTED **N
+OT** THE COMMAND OUTPUT)
$output = $exp->before();
print "output is: $output\n";
# Destroy the expect object
$exp->soft_close();
# Output stdout
#print "output is: @output\n";
The perl script just prints the commands I want to run without the actual output from the commands on the SBC themselves!!
Does any one have any ideas what I'm doing wrong in the Perl script?
Much appreciate any help you can provide