This is an example script that communicates with a Cisco ASA, it is different than the router interaction script because the command structure is different on an asa. Below is a partial example that will get you to log output of a command to a file, you can choose which commands you would like to have sent:
#!/usr/bin/perl -w
use Expect;
use strict;
# Variables used
#This example is for TACACS authentication but works with local username authentication as well.
my $username = "username";
my $password = "password";
my $host = "192.168.0.1";
my $host2 = "192.168.0.2";
my @hosts;
my $backupdir = "/logs";
my $timeout = 10;
my @output;
push @hosts, "$host", "$host2";
foreach $host (@hosts) {
my $filename = "$host.txt";
my $filepath = "$backupdir/$filename";
my $command = Expect->spawn("ssh $username\@$host");
$command->expect($timeout, -re => "password:") or die("Failed to get password prompt");
print $command "$password\r";
#Give it a second to register
sleep 1;
print $command "enable\r";
$command->expect($timeout, -re => "Password:") or die("Did not get a password prompt\n");
print $command "$password\r";
print $command "terminal pager 0\r";
$command->log_file("$filepath");
print $command "show run object-group\r";
my $redo = 1;
while($redo)
{ $command->clear_accum();
$command->expect(1,
[ qr/More/ => sub { my $comand = shift; print $command "\r"; exp_continue; } ],
[ qr/#/ => sub { my $exp = shift; $redo = 0; exp_continue; } ],
);
}
print $command "exit\r";
$command->soft_close();
$command->log_file(undef);