Perl Script

Posted on 2009-02-18
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

Question by:d_asselin
    LVL 39

    Accepted Solution

    How is your mysql table setup?
    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) {
          or warn "INSERT error: $DBI::errstr\n";

    Open in new window


    Author Comment

    Please close this question I found my answer

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
    Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now