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
| #!/usr/bin/perl
use DBI;
use CGI;
$co = new CGI;
#print $co->header;
$database="arpwatch";
$hostname="localhost";
$login="arpwatch";
$mdp="mdp";
$dsn = "DBI:mysql:database=$database;host=$hostname";
$dbh = DBI->connect($dsn, $login, $mdp) or die "Echec de connexion";
#ouverture du fichier :
open fichier,"< /collecte/sauveur3-arpwatch.dat" or die "Le fichier n'existe pas !";
while ($ligne = <fichier>)
{
if($ligne =~ /(\w+)\t(\w+)\t(\w+)\t(\w+)/)
{
my $mac = $1;
my $ip = $2;
my $epoch = $3;
my $texte = $4;
}
$req = "INSERT INTO titi (mac, ip, epoch, texte) VALUES ($1, $2, $3, $4);";
$sth = dbh->prepare($req);
$sth->excute();
}
close (FILE, "/collecte/sauveur3-arpwatch.dat");
$sth->finish;
$dbh->disconnect; |