############# CONNECT TO THE SWITCH AND UPDATE THE CONFIG FILE #########################################
my $tftp_server = "172.16.0.100";
my $switch = "172.16.1.2";
my $user = "Cisco";
my $password = "Cisco";
my $dest_file = "startup-config";
my $copy_tftp = "copy tftp start\n$tftp_server\n$config_file\n$dest_file\n";
#my $matchop = $obj->prompt('/(?m:^\s*--More-- or \(q\)uit/');
# \s matches a whitespace
# \S is a negated \s and matches any non-whitespace character [^\s]
# ? indicates to match 1 or 0 times, and is placed after the character to match
# ^ indicates to match at the beginning of the line
# $ indicates to match at the end of the line
my $session = Net::Telnet::Cisco->new(
Host => $switch,
Input_log => "input.log",
Output_log => "output.log",
Timeout => 30);
$session->always_waitfor_prompt;
$boolean = $session->ignore_warnings;
$boolean = $session->ignore_warnings($boolean);
# Wait for the username prompt and enter username
@out = $session->waitfor('/Username:.*$/');
print "@out
\n";
@out = $session->print($user);
print "@out
\n";
# Wait for the password prompt and enter the password
@out = $session->waitfor('/Password:.*$/');
print "@out
\n";
@out = $session->print($password);
print "@out
\n";
@out = $session->cmd("copy tftp start\n$tftp_server\n$config_file\n$dest_file\n");
print "@out
\n";
@out = $session->cmd("delete vlan.dat\n\n\n");
print "@out
\n";
@out = $session->cmd("reload\n\n");
print "@out
\n";
@out = $session->close;
}