Using perl Syntax Highlighting
#!/usr/bin/perl -w
use strict;
use Expect;
my $telnetUsername = "userx";
my $telnetPassword = "passy";
my $telnetPasswordEna = "passena";
my @telnetServer = ("server1", "server2", "server3");
my $fileToFetch = "startup-config";
my $tftpServer = "IP_tftp_server";
my $timeout = 10;
for (my $i=0; $i<3; $i++) {
print "Conexióon $telnetServer[$i]\n";
my $command = 'telnet';
# Create the Expect object
my $exp = Expect->spawn($command, $telnetServer[$i]) or die "Cannot spawn telnet command \n";
$exp->log_file("testlog");
$exp->expect($timeout, ["Username:"]);
$exp->send("$telnetUsername\n");
$exp->expect($timeout, ["Password:"]);
# Sent the telnet password
$exp->send("$telnetPassword\n");
# Wait for telnet prompt
$exp->expect($timeout, [" >"]);
# mode super-user
$exp->send("ena\n");
$exp->send("$telnetPasswordEna\n");
#mete los valores oportunos
$exp->send("copy startup-config tftp:\n");
#$exp->expect($timeout, ["Address or name of remote host []?"]);
$exp->send("$tftpServer\n");
$exp->expect($timeout, ["Destination filename [ ]?:"]);
$exp->send("\n");
$exp->send("exit\n");
$exp->soft_close();
}
use strict;
use Expect;
my $telnetUsername = "userx";
my $telnetPassword = "passy";
my $telnetPasswordEna = "passena";
my @telnetServer = ("server1", "server2", "server3");
my $fileToFetch = "startup-config";
my $tftpServer = "IP_tftp_server";
my $timeout = 10;
for (my $i=0; $i<3; $i++) {
print "Conexióon $telnetServer[$i]\n";
my $command = 'telnet';
# Create the Expect object
my $exp = Expect->spawn($command, $telnetServer[$i]) or die "Cannot spawn telnet command \n";
$exp->log_file("testlog");
$exp->expect($timeout, ["Username:"]);
$exp->send("$telnetUsername\n");
$exp->expect($timeout, ["Password:"]);
# Sent the telnet password
$exp->send("$telnetPassword\n");
# Wait for telnet prompt
$exp->expect($timeout, [" >"]);
# mode super-user
$exp->send("ena\n");
$exp->send("$telnetPasswordEna\n");
#mete los valores oportunos
$exp->send("copy startup-config tftp:\n");
#$exp->expect($timeout, ["Address or name of remote host []?"]);
$exp->send("$tftpServer\n");
$exp->expect($timeout, ["Destination filename [ ]?:"]);
$exp->send("\n");
$exp->send("exit\n");
$exp->soft_close();
}
Coloreado en 0.006 segundos, usando GeSHi 1.0.8.4
Tengo configurada la siguiente línea: $exp->log_file("testlog");
Esa línea hace como una especie de print de todo lo que hace el script, eso no lo deseo.
Espero que me puedan ayudar, muchas gracias a todos de antemano.
Un cordial saludo.