We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Perl Script

d_asselin
d_asselin asked
on
Medium Priority
204 Views
Last Modified: 2012-05-06
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
Comment
Watch Question

Top Expert 2009
Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Please close this question I found my answer
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.