Place IP addresses of the routers, one per line, in file routers.txt. This file must be in the same directory as the script. Remember, you put your username, password and enable password in the script in clear text, so do not forget "chmod 700 "
#!/usr/bin/perl use Net::Telnet::Cisco; my $myfile="./routers.txt"; open (FH, $myfile) || die "Can not open $myfile\n"; while () { chomp; my $switchname=$_; print "$switchname\n";
my $session = Net::Telnet::Cisco->new(Host => $switchname,Input_log => "$switchname.log");
# Replace username and password below with real username and password
$session->login('username', 'password'); # Enable mode if ($session->enable("enable password") ) { # insert your enable passowrd @output = $session->cmd('configure terminal'); @output = $session->cmd('logging source-interface loopback 0'); print @output; @output = $session->cmd('exit'); @output = $session->cmd("copy run startup-config\n\n"); print @output; } else { warn "Can't enable: " . $session->errmsg; } $session->close; }
Use at your own risk.
No comments:
Post a Comment