Databases
cancel
Showing results for 
Search instead for 
Did you mean: 

search syslog for errors with perl

SOLVED
Go to solution
simon peter
Occasional Contributor

search syslog for errors with perl

Hi
I have a perl script which searches syslog for error message.In this case i have just used "vmunix" but what i want to be able to do is only list error's for set date.

For example if i run script now it will only check for messages in the last 24 hours.

Regards
Simon
2 REPLIES
Steven Mertens
Trusted Contributor

Re: search syslog for errors with perl

hi,

If you only wanna see entries
of today

grep $(date | awk '{print $2,$3}') /var/adm/syslog/syslog.log

But maybe it is better you
make a script that renames
your logfiles on daily base.

rgds.
Steven
Vincent Stedema
Esteemed Contributor
Solution

Re: search syslog for errors with perl

Hi Simon,

INAPH
(I'm Not A Perl Hacker)
but I'll give it a try.

I don't know which version of Perl you're using, so I'll try and keep it simple (and backwards compatible with Perl 4, I hope)...

-----------------------
#!/usr/contrib/bin/perl
@months = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec" );

($day,$month,$string)=@ARGV[0,1,2];

open(LOGFILE,"while() {
/^$months[$month-1]\s+$day\s+.*$string/ && print;
}

close(LOGFILE);
-------------------------

The syntax on the command prompt is:

#scriptname

e.g.

#logsearch 18 12 vmunix

will yield all entries in the syslog of December 18th containing the string "vmunix". Note that you should put quotes around a search string that contains white space...

I'm sure procura will come up with a better script, but that's the essence of Perl: there's more than one way to do it :-)

Hope this helps.

Regards,

Vincent