oldshield schrieb:
Anyone have a working script for this?
Yep! Save the following in "Configuration Manager --> F5 Loadbalancer --> Inforamtion --> Capture Running Config. Script" and don't forget to configure Username/Password in Spectrum.
#!/opt/SPECTRUM/bin/perl -w
# Error Codes:
# 0 = Success
# 255 = Usage error
# 254 = Invalid timeout value
# 252 = Login error
# 249 = Exec prompt not found error
# 244 = Error retrieving configuration
# 245 = Insufficient privileges
# 253 = Unexpected output
#
use strict;
use warnings;
use Net::SSH::Expect;
$ENV{'PATH'} = "/usr/bin:". $ENV{'PATH'};
### Main ###
if( $#ARGV != 4 && $#ARGV != 5 )
{
my $errorCode = 1;
my @data;
my $errorString = "\nHost $ARGV[0]: \n";
($errorCode, @data) = GetConfig( $ARGV[0], $ARGV[1], $ARGV[2], $ARGV[3], 2, 2 );
}
sub GetConfig
{
my $deviceIP=shift;
my $user=shift;
my $pass=shift;
my $epass=shift;
my $login_timeout=shift;
my $capture_timeout=shift;
my @config;
my $msg;
my $ssh = Net::SSH::Expect->new ( host => $deviceIP,
user => $user,
password=> $pass,
raw_pty => 1,
no_terminal => 0,
timeout => $login_timeout
);
my $login_output;
eval { $login_output = $ssh->login(); };
$ssh->send( "tmsh save /sys config file config.scf no-passphrase" );
sleep 5;
$ssh->send( "cat /var/local/scf/config.scf" );
$ssh->timeout( 2 );
$ssh->peek(0);
while( my $line = $ssh->read_line() )
{
if( $line !~ /config.scf/ )
{
print "$line\n";
}
}
$ssh->close();
}