# BackUp Cisco router Config with perl Scripting

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

## 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');
$telnet->print($password);
$telnet->waitfor('/Router>$/i');
$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!

1. 1
2. 2
Rutin
19
3. 3
khawk
15
4. 4
5. 5
A4L
13

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633744
• Total Posts
3013654
×