init III
This commit is contained in:
87
Perl Cisco konfigurieren/router.pl
Normal file
87
Perl Cisco konfigurieren/router.pl
Normal file
@@ -0,0 +1,87 @@
|
||||
#!/bin/perl
|
||||
|
||||
use Net::Telnet::Cisco;
|
||||
|
||||
sub LOG ($);
|
||||
|
||||
open RTR, "<router_list.txt";
|
||||
while (<RTR>) {
|
||||
if ($_ =~ /^#/) {
|
||||
print $_;
|
||||
next;
|
||||
}
|
||||
chomp;
|
||||
($ip,$user,$pass,$enable,$wait)=$_=~/^(.*),(.*),(.*),(.*),(.*)$/i;
|
||||
$wait=10 if ($wait eq "");
|
||||
# print "$ip,$user,$pass,$enable,$wait\n";
|
||||
@routers=(@routers,[$ip,$user,$pass,$enable,$wait]);
|
||||
}
|
||||
close RTR;
|
||||
|
||||
my $session;
|
||||
my @output;
|
||||
|
||||
my ($ss,$mm,$hh,$dd,$mon,$yy,$we,$doy,$st)=localtime;
|
||||
$mon++;
|
||||
$yy+=1900;
|
||||
$dd = '0' . $dd if ($dd < 10);
|
||||
$mon = '0' . $mon if ($mon < 10);
|
||||
my $date=$yy . "-" . $mon . "-" . $dd;
|
||||
|
||||
my @commands;
|
||||
open CMD, "<router_config.txt";
|
||||
foreach (<CMD>) {
|
||||
if ($_ =~ /^#/) {
|
||||
print $_;
|
||||
next;
|
||||
}
|
||||
chomp unless ($_ =~ /^\n$/);
|
||||
@commands=(@commands,$_);
|
||||
}
|
||||
close CMD;
|
||||
|
||||
|
||||
foreach my $router (@routers) {
|
||||
print "\nVerbinde zu $$router[0]\n";
|
||||
|
||||
# LOG "Verbindungsversuch zu $$router[0]";
|
||||
|
||||
next unless ($session = Net::Telnet::Cisco->new(Host => "$$router[0]", Errmode=>'return'));
|
||||
|
||||
# LOG "Verbindung zu $$router[0] erfolgreich hergestellt";
|
||||
|
||||
if ($$router[1] eq '') {
|
||||
print "sende Passwort\n";
|
||||
$session->login(Password => "$$router[2]");
|
||||
}
|
||||
else {
|
||||
print "sende user, pw\n";
|
||||
$session->login(Name => "$$router[1]", Password => "$$router[2]");
|
||||
}
|
||||
|
||||
print "enable\n";
|
||||
$session->cmd("enable\n$$router[3]") if ($$router[3] ne "");
|
||||
|
||||
# LOG "$$router[0] !!! Sende Befehle";
|
||||
|
||||
foreach (@commands) {
|
||||
print "$$router[0] $_\n";
|
||||
@output = $session->cmd(String=>"$_", Timeout => 1);
|
||||
}
|
||||
|
||||
# LOG "Ausgabe des Routers\n@output";
|
||||
|
||||
# LOG "Ende und Speichern\n-------------------------------------------";
|
||||
$session->cmd("end");
|
||||
$session->cmd("wr");
|
||||
sleep ($$router[4]);
|
||||
|
||||
print "\n\n";
|
||||
|
||||
}
|
||||
|
||||
sub LOG {
|
||||
open LOGG, ">>connect.log";
|
||||
printf LOGG "$_[0]\n";
|
||||
close LOGG;
|
||||
}
|
||||
Reference in New Issue
Block a user