Monks,
I'm trying to parse a syslog for usernames, but I'm having problems with my code. Here is what the log info looks like that I'm parsing:
Sep 12 17:30:02 nt-ca-na CA(Domain-CA): Certificate name 'jsmith.2048'
+ added to database.
Sep 12 20:09:37 nt-ca-na CA(Domain-CA): Certificate name 'ksmith.2048'
+ added to database.
Sep 12 21:25:30 nt-ca-na CA(Domain-CA): Certificate name 'ssmith.2048'
+ added to database.
I want to match just on the usernames (jsmith.2048) that were added. The code below works, but it enters all the usernames into the @certs array. When I do a
print "@certs[0]" I get the following results:
'jsmith.2048''ksmith.2048''ssmith.2048'
What should I do to place each array into it's own entry?
Thanks,
Dru
#!/usr/bin/perl -w
use strict;
my $calog = "/var/log/ca/ca.log";
my $line;
my @certs;
open LOG, "$calog" or die "Can't open $calog: $!\n";
while ($line = <LOG>){
if ($line =~ m/added/) {
@certs = $line =~ m!\'[-.\w]+\'!g;
print @certs;
} #end if
} #end while
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.