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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#!/usr/bin/perl
#
use warnings;
use strict;
use DBI; # Charger le module DBI
use File::Copy; # Charger le module File Copy
use Sys::Hostname;
# declaration des variables
#
#
my ($critere, $requete, $valeur, $dbh, $sth);
my ($host_name, $host_alias, $host_address, $comment_id);
my ($osname);
my ($nbelememt);
my @enr = ();
my @tbl_host_name = ();
my @tbl_host_alias = ();
my @tbl_host_address = ();
my @tbl_comment_id = ();
my @tbl_osname = ();
my $chiffre = 0;
# Parametres de connexion au serveur MYSQL
#
#
my $BaseDeDonnees = "centaudit";
my $NomHote = "localhost";
my $login = "root";
my $MotDePass = "xxxxxxx";
# Extraction des données MYSQL
#
#
# Connection à la base de données mysql
$dbh = DBI->connect( "dbi:mysql:dbname=$BaseDeDonnees;host=$NomHote;",$login, $MotDePass,{'PrintError'=>0} )
or die "Connection impossible à la base de donnees $BaseDeDonnees\n" ;
# Requete mysql
$requete = "SELECT host_name,host_alias,host_address,comment_id,osname
FROM host left join hardware on host.host_name=hardware.NAME left join comment on host.host_name=comment.host_id
WHERE host_alias LIKE 'Serveur Physique'
ORDER BY host_name";
$sth = $dbh->prepare($requete);
$sth->execute();
while ( ($host_name, $host_alias, $host_address, $comment_id, $osname) = $sth -> fetchrow_array) {
push(@tbl_host_name, "$host_name");
push(@tbl_host_alias, "$host_alias");
push(@tbl_host_address, "$host_address");
push(@tbl_comment_id, "$comment_id");
push(@tbl_osname, "$osname");
print "$osname\n";
}
$sth->finish;
# Déconnection à la base de données
$dbh->disconnect(); |
Partager