Operating System - HP-UX
1849923 Members
2792 Online
104047 Solutions
New Discussion

Re: Need Help in a Script

 
Uday_S_Ankolekar
Honored Contributor

Need Help in a Script


I want to check possible warning messages from syslog file for the last seven days.
I'm using grep command to match the words like Error, Warning, Fail etc..
This is my command in script.
grep -Ei "err|warn|panic|crit|fail" /var/adm/syslog/syslog.log
I also want to ignore some words those have 'err' letters( Ex.RFErr ) How can I do this in a single grep command??.
And I would like to check syslog file for these errors only for last seven days.

Thanks in Advance



Good Luck..
9 REPLIES 9
Paula J Frazer-Campbell
Honored Contributor

Re: Need Help in a Script

Hi

grep -v will ignore.

See man grep

HTH

Paula
If you can spell SysAdmin then you is one - anon
Rita C Workman
Honored Contributor

Re: Need Help in a Script

Here's a little script that will check for some things I like to be alerted for...I have it email me the message when it finds one.
Modify it as you may want...if you like it.

I set the job up and cron'd it to check the syslog file every 10 minutes...

Regards,
Rita
Sachin Patel
Honored Contributor

Re: Need Help in a Script

Hi
cat file |grep -v "word"

Sachin
Is photography a hobby or another way to spend $
Paula J Frazer-Campbell
Honored Contributor

Re: Need Help in a Script

Hi
To check the log file over a specific period of days then you will have to calculate the date "X" days ago, attached is a script which when run as:- <scriptname> x
x being the number of days in the past you require will return that date you can then grep out what you require from that date forward.

Script is one that Tom Danzig posted a while ago. - Thanks Tom.

In your script;-

7 - use result to grep out.
6 - use result to grep out.
5 - use result to grep out.

And so on.

Just an idea

Paula




This scrip was from Tom danzig

If you can spell SysAdmin then you is one - anon
Satish Y
Trusted Contributor

Re: Need Help in a Script

grep -Ei "err|warn|panic|crit|fail" /var/adm/syslog/syslog.log | grep -v -i err > /tmp/syslogerr.txt

For grepping errors for last sevendays u need to write a script for that by grepping fileds in date command and decrese the day value for each previous day. You can't do that in single grep command.

I have attached a script for 2 days(today and yesterday.

Cheers...
satish.
Difference between good and the best is only a little effort
Uday_S_Ankolekar
Honored Contributor

Re: Need Help in a Script

Thanks. I really appriciate your help.

Good Luck..
Abel Berger
Regular Advisor

Re: Need Help in a Script

Hi Uday,

1 ) You can use the find command joint the
mtime parameter for make a copy of file syslog.log older than 7 days.

2 ) Later, use the grep command in this copy.

I Don?t remember the find syntaxe.

Anybody remember ??

more less : find /var/adm/syslog/syslog.log -mtime +7 -exec cp......\;

I hope this help !

Regards,

Abel Berger

Uday_S_Ankolekar
Honored Contributor

Re: Need Help in a Script

Abel,
You can use find with -depth. the proper syntex would be

find -depth -mtime +7 -exec

Thanks thou...
Good Luck..
Robin Wakefield
Honored Contributor

Re: Need Help in a Script

grep -Ei "[^a-z]err[^a-n,p-z]|warn|panic|crit|fail"

will match on "err" or "error" but not, say, "interrupt"

Robin.