Re: log tailing
| From: | Daniel Brown | Date: | Sat, 30 Jun 2012 18:30:36 +0000 |
| Subject: | Re: log tailing | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-318349@lists.php.net to get a copy of this message | ||
On Fri, Jun 29, 2012 at 4:49 AM, Mihamina Rakotomandimby
<mihamina@rktmb.org> wrote:
[snip!]
>
> Typically, a log line like:
> Jun 29 11:24:10 dev5 sshd[12775]: Accepted password \
> for dev5 from 192.168.0.12 port 50544 ssh2
>
[snip!]
> So that I can:
>
> INSERT INTO ssh_activity \
> VALUES ('2012-06-29 11:24:10', '192.168.0.12')
>
> I just need help on the right regexp function to use.
> Would you know some PHP/regexp tutorials for that?
You could take the pattern-matching load off of PHP entirely if
you used something along these lines. Just remember to adjust and
clean up as necessary.
<?php
$ssh_entries = explode(PHP_EOL,trim(`tail /var/log/syslog | awk
{'print $1,$2,$3 "|" $5 "|" $11'}`));
foreach ($ssh_entries as $s) {
$l = explode('|',$s);
// Remember to do whatever sanity necessary!
$sql = "INSERT INTO ssh_activity
VALUES('".$l[0]."','".$l[1]."','".$l[2]."')";
}
?>
--
</Daniel P. Brown>
Network Infrastructure Manager
http://www.php.net/