Hope someone can help me here. Looking to redo my bash ssh script for cisco devices, and add on to it. Basically, my idea is to have an SSH to log me to the device in enable mode (so i can do regular admin stuff as usual ) and run in silent mode a backup of the device ( where the txt file is the hostname of the devices ) .
Best I have done so far , and haven`t test it on live equipment is :
#!/usr/bin/perl
use warnings;
use strict;
use Expect;
use Data::Dumper;
my $user = $ARGV[0];
my $pw = $ARGV[1];
my $host = $ARGV[2];
my $cmd = 'sh run';
my $exp = new Expect;
$exp->log_file("SSHLOGFILE.txt");#How do i make this to be the hostname of the device though
$exp->log_stdout(0);
$exp->raw_pty(1);
my $cli = "/usr/bin/ssh $user\@$host -o StrictHostKeyChecking=no -q $cmd";
#not sure about this
$exp->spawn($cli) or die "Cannot spawn $cli: $!\n";
$exp->expect(5,
[ qr /ssword:*/ => sub { my $exph = shift;
$exph->send("$pw\n");
exp_continue; }] );
my $read = $exp->exp_before();
chomp $read;
print Dumper($read);
$exp->soft_close();
I can install RANCID as i have no root on the jump host , I can run the scripts outside the jumphost , and Perl is my only option as I can have the modules on a local library.