Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 196
  • Last Modified:

Perl Script

Hi All
 First post

   In a nut shell I'm looking for a perl script to parse
syslog and write to mysql dn

 Thank you

Dan
0
d_asselin
Asked:
d_asselin
1 Solution
 
Adam314Commented:
How is your mysql table setup?
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use Parse::Syslog;
 
my $db_name='your_database_name_here';
my $db_host='your_database_host_here';
my $db_user='your_database_username_here';
my $db_pass='your_database_password_here';
my $log_filename='/your/log/file/name/here';
 
my $dbh = DBI->connect("DBI:mysql:database=$db_name;host=$db_host", $db_user, $db_pass) or die "Could not connect: $DBI::errstr\n";
my $syslog=new Parse::Syslog($log_filename);
 
my $sth=$dbh->prepare(
  'INSERT INTO table (timestamp, host, program, pid, text) VALUES (?, ?, ?, ?, ?)');
 
while(my $sl = $syslog->next) {
    $sth->execute(
      $sl->{timestamp},
      $sl->{host},
      $sl->{program},
      $sl->{pid},
      $sl->{text})
      or warn "INSERT error: $DBI::errstr\n";
}

Open in new window

0
 
d_asselinAuthor Commented:
Please close this question I found my answer
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now