Jump to content
  • Advertisement
Sign in to follow this  
Kenster

BackUp Cisco router Config with perl Scripting

This topic is 3638 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!