scripting for error messages to grep in logs.

dear ,

Hai this is venu from india

i want script for fetching error messages in log file for particular time , date and it will be save one file
venu gopalAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JesterTooCommented:
venu,

You need to provide more information in order for someone to give you a useful answer... for insance:

1.  Which shell to use
2.  File name of log file(s) to search
3.  Where to save output file
4.  Will the script take command line input for parameters or will it prompt the user
5.  A sample log file will also be extremely valuable in order to formulate a solution
0
arnoldCommented:
how are the logs generated and by what applications. Look at sending your log events through syslog/rsyslog and have it process those logs and do what you need.
Additional suggestions to the ones provided by Jester.
0
murugesandinsShell_script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX C C++ CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NTCommented:
Sample command used:
#!/bin/bash
SAVE_ERROR_FILE=''`/bin/date "+%d_%b_%Y_%H_%M_%S_%N"`''"_Error_Message_From_Log.txt"
while [ 1 ]
do
	if test -f "$SAVE_ERROR_FILE"
	then
		/bin/sleep 1
		SAVE_ERROR_FILE=''`/bin/date "+%d_%b_%Y_%H_%M_%S_%N"`''"_Error_Message_From_Log.txt"
	else
		break
	fi
done
if test -f /tmp/Error_Log.txt
then
	/bin/egrep -i "error" /tmp/Error_Log.txt | /usr/bin/tee -a "$SAVE_ERROR_FILE"
	echo "Error output written in following file:"
	echo "$SAVE_ERROR_FILE"
else
	echo "/tmp/Error_Log.txt No such file" | /usr/bin/tee -a "$SAVE_ERROR_FILE"
fi

Open in new window

Above script will work for /bin/ksh or /bin/bash
Script written based on following assumption of log file content:
$ cat /tmp/Error_Log.txt
25/Apr/2000 01:00 AM PASS
25/Apr/2001 02:00 AM Error txt file not found
25/Apr/2002 03:00 AM PASS
25/Apr/2003 04:00 AM Error
25/Apr/2004 05:00 AM Error
25/Apr/2005 06:00 AM PASS
25/Apr/2006 07:00 AM Error
25/Apr/2017 01:00 AM PASS

Open in new window

Sample output:
$ /bin/chmod u+x ./CheckError_FromLog.sh
$ ./CheckError_FromLog.sh
25/Apr/2001 02:00 AM Error txt file not found
25/Apr/2003 04:00 AM Error
25/Apr/2004 05:00 AM Error
25/Apr/2006 07:00 AM Error
Error output written in following file:
25_Apr_2017_15_19_50_867731900_Error_Message_From_Log.txt

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
murugesandinsShell_script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX C C++ CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NTCommented:
Closing this query for
1. Question inactive
2. Tested and given resolved answer.
Comment if any objection.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.