1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#!/usr/bin/perl
use strict; #Permet d utiliser des variables de type globales
#use Net::Telnet; #Package permettant de creer une session telnet
use Net::Telnet::Cisco;
my $username="user_script_LAN"; #Le loggin
my $passwd="read-only"; ####
my $Ligne_Fichier_Adresse_IP; #Contient la ligne courante du fichier matos
my $Ligne_Fichier_Config;#Contient la ligne courante du fichier power
my $Nom_switch_Courant;
my $Adresse_IP_courante;
my $Resultat_ping;
#############################################################################
##### ICI on recupere les configurations
#############################################################################
open(Fichier_Adresse_IP,"</var/home/rappju/projet_3/base_Lan-19-05-06.txt") || die ("probleme fichier adresse ip :\n $! ");
open(Fichier_PB_IP,">/var/home/rappju/projet_3/prob_IP") || die ("probleme fichier adresse ip :\n $! ");
while ($Ligne_Fichier_Adresse_IP = <Fichier_Adresse_IP> )
#On parcourt le fichier type_matos_lan.txt pointe par son descripteur Fichier_Materiel
{
next if (($Ligne_Fichier_Adresse_IP) =~ m/^$/);
#Cette ligne permet d'omettre toutes les lignes vides !!! On ne considere donc que les lignes utiles
{
if(($Ligne_Fichier_Adresse_IP) =~ /(.*);(.*);/)
{
$Nom_switch_Courant=$1;
$Adresse_IP_courante=$2;
print"\n##Nom_switch_Courant[$Nom_switch_Courant]#Adresse_IP_courante[$Adresse_IP_courante]###\n";
require sous_fonc_ping;
$Resultat_ping=(&sous_fonc_ping::Fonc_Ping($Adresse_IP_courante));
if($Resultat_ping =~ /[1-9] packets received/)#Spartacus
{
my $telnet = Net::Telnet::Cisco->new( Timeout=>5, ErrMode => 'return', Prompt => '/.*#/');
$telnet->open(Host=>$Adresse_IP_courante);
$telnet->login($username, $passwd);
my @results = $telnet->cmd("copy startup-config tftp://10.45.58.19\n\n\n\n");
$telnet->close;
}
else
#Adresse IP non joignable
{
print"\n#Nom_switch_Courant$Nom_switch_Courant#Adresse_IP_courante$Adresse_IP_courante#\n";
print Fichier_PB_IP "$Nom_switch_Courant;$Adresse_IP_courante;\n";
}
}
else
#Cas ou l on a un probleme de recuperation des adresses IP et nom
{
#On fait rien
}
}#Cas des lignes non vides
}#Fin while qui parcourt le fichier d adressage
close Fichier_Adresse_IP;
close Fichier_PB_IP; |
Partager