🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

BackUp Cisco router Config with perl Scripting

Started by
-1 comments, last by Kenster 15 years, 8 months ago
I've seen many post of such as was able to make a nearly perfect script for it. So far I have this

$hostname = '1.1.1.1';
$password = 'service';
$remoteHostname = '1.1.1.1';
$emailHost = '';
$sendTo = '';

use Net::Telnet;
$telnet = new Net::Telnet ( Timeout=>10,Errmode=>'die');
$telnet->open($hostname);
$telnet->waitfor('/Password: $/i');
print ("printing password");
$telnet->print($password);
$telnet->waitfor('/Router> $/i');
print ("getting admin rights");
$telnet->print('en');
$telnet->waitfor('/Password: $/i');
$telnet->print($password);
print ("printing password");
$telnet->waitfor('/Router#: $/i');
$telnet->print('copy running-config TFTP');
print ("running copy command");
$telnet->waitfor('/Address or name of remote host []? $/i');
print ("writing address of remote host");
$telnet->print($remoteHostname);
($wkday,$month,$day,$time,$year) = split(/\s+/, localtime);
$telnet->waitfor('/Destination filename [router-confg]? $/i');
print ("giving date as $year/$month/$date");
$telnet->print('$year/$month/$date-config');
$output = $telnet->waitfor('/!! $/i');
if ($output)
{
print ("true");
}
else
{
open (MAIL, "|$mailprog") || die 'Could not open mail program';
print MAIL "To: $sendto\n";
print MAIL "From: $emailhost\n";
print MAIL "Subject: CISCO LOG BACKUP ALERT\n\n";
print MAIL "Check CISCO router as the backup failed!";
close (MAIL)
print ("false");
}
print $output;
Problem is down at the end. When a config is backed up it either says, ... Failed blah blah or, !! Backed up Config blah blah. Then goes to a near line. The WaitFor can only read where a cursor is and not previous lines. I need some type of protection that if it fails, it will alert me. Currently, I just say if it times out(Any where) it sends to me, but that isn't how I wanted to do it. Any suggestions would be greatful. Thanks!

This topic is closed to new replies.

Advertisement