dcthehole has asked for the wisdom of the Perl Monks concerning the following question:
I am currently trying to scan a log file on my server. I want to match my regex to my file name. This is the error I am getting.
Error opening D:\ServerTools\Logs\ServerLog\((\d+)-(\d+)-(\d+)@(\d+)-( +\d+)\.log ): Invalid argument at script.pl line 109
Here is my actual script
#!/usr/bin/perl -w use DBI; use File::Tail; our $bWin; BEGIN { $bWin = ($^O eq "MSWin32") ? 1 : 0; } &Loop; sub Loop { print "Updating Server Log -> DB\n"; &Update_DB_Actions; } sub Update_DB_Actions { my $dbh = DBI->connect('DBI:mysql:database=arma3;host=localhost',' +root','root') || die "Could not connect to database: $DBI::errstr"; my $filename = q{ServerLog\((\d+)-(\d+)-(\d+)@(\d+)-(\d+)\.log +)}; # my ($sec,$min,$hour,$day,$month,$year) = (localtime)[0,1,2,3,4,5 +]; # my $filename = sprintf("ServerLog(%02d-%02d-%04d).log",$month+1, +$day,$year+1900); my $log = "D:\\ServerTools\\Logs\\$filename"; my $qu_re1 = q{(.?) started server @ (\d+):(\d+):(\d+)}; my $qu_re2 = q{(.?) restarted server @ (\d+):(\d+):(\d+)}; my $qu_re3 = q{(.?) stopped server @ (\d+):(\d+):(\d+)}; $file = File::Tail->new($log); while (defined($line=$file->read)) { my $sql = "INSERT INTO `actions` (log) VALUES (?)"; $insa = $dbh->prepare($sql) or die $!; $insa->execute($line); print "Inserted Action!\n"; } &Loop; }
Also I want to add a way to delete the log file after it is uploaded to the db. Any suggestions?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help w/ regex in filename
by davido (Cardinal) on Jul 06, 2013 at 04:02 UTC | |
by dcthehole (Novice) on Jul 06, 2013 at 04:10 UTC | |
by davido (Cardinal) on Jul 06, 2013 at 04:14 UTC | |
by Anonymous Monk on Jul 06, 2013 at 07:35 UTC | |
|
Re: Help w/ regex in filename
by kcott (Archbishop) on Jul 06, 2013 at 04:54 UTC | |
by davido (Cardinal) on Jul 06, 2013 at 05:12 UTC | |
by kcott (Archbishop) on Jul 06, 2013 at 05:52 UTC | |
by dcthehole (Novice) on Jul 06, 2013 at 05:20 UTC | |
by davido (Cardinal) on Jul 06, 2013 at 05:41 UTC | |
|
Re: Help w/ regex in filename
by Athanasius (Archbishop) on Jul 06, 2013 at 04:13 UTC | |
by dcthehole (Novice) on Jul 06, 2013 at 04:16 UTC | |
|
Re: Help w/ regex in filename
by Anonymous Monk on Jul 06, 2013 at 03:58 UTC |