Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
General
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