Shell Script for getting Errors

Hi Experts,

I have a systemout.log file where I need to monitor for the errors. When I do grep for the errors , it will list me all the errors repeatedly. I am looking for a script where it grep the Error and count it.

I use grep "E" systemout.log

[9/17/12 1:00:00:162 EDT] 0000009a LdapRegistryI E   No user sadmin found
[9/17/12 1:00:00:171 EDT] 0000009a LdapRegistryI E   SECJ0336E: Authentication failed for user sadmin because of the following exception
[9/17/12 1:00:00:194 EDT] 0000009a LTPAServerObj E   SECJ0369E: Authentication failed when using LTPA. The exception is No user sadmin found.
[9/17/12 1:00:00:235 EDT] 0000009a LdapRegistryI E   No user sadmin found
[9/17/12 1:00:00:236 EDT] 0000009a LdapRegistryI E   SECJ0336E: Authentication failed for user sadmin because of the following exception com.ibm.websphere.security.PasswordCheckFailedException: No user sadmin found
[9/17/12 1:00:00:237 EDT] 0000009a LTPAServerObj E   SECJ0369E: Authentication failed when using LTPA. The exception is No user sadmin found.
[9/17/12 5:50:30:922 EDT] 00000070 servlet       E com.ibm.ws.webcontainer.servlet.ServletWrapper run [Servlet Error]-[class java.lang.ClassNotFoundException: org.apache.jsp._textOnlyStyles]: java.lang.ClassNotFoundException: class java.lang.ClassNotFoundException: org.apache.jsp._textOnlyStyles
[9/17/12 7:01:26:998 EDT] 0000009a webcontainer  E com.ibm.ws.webcontainer.WebContainer handleRequest SRVE0255E: A WebGroup/Virtual Host to handle /favicon.ico has not been defined.
[9/17/12 7:01:27:033 EDT] 0000009b webcontainer  E com.ibm.ws.webcontainer.WebContainer handleRequest SRVE0255E: A WebGroup/Virtual Host to handle /favicon.ico has not been defined.
[9/17/12 7:01:28:033 EDT]000000c4 servlet       E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E: Uncaught exception created in one of the service methods of the servlet /jsp/Search.jsp in application AP_JSP. Exception created : com.ibm.websphere.servlet.error.ServletErrorReport:
[9/17/12 7:50:00:168 EDT] 0000009a LdapRegistryI E   No user sadmin found

Thanks.
07592161981mAsked:
Who is Participating?
 
simon3270Connect With a Mentor Commented:
If all "E" entries have a space either side of the E (they seem to in your examples), then:

    grep " E " systemout.log | sed 's/^.* E //' | sort | uniq -c

will count unique error logs.
0
 
farzanjCommented:
If you want to count the occurences, you need to use option -c

grep -c "E" filename
0
 
07592161981mAuthor Commented:
I want to use tools like sed/find/grep/awk.

I would like to see the output like this:

3 - No user sadmin found
6 -  Authentication failed when using LTPA
2 - SRVE0068E: Uncaught exception created in one of the service methods
3 -  SRVE0255E: A WebGroup/Virtual Host to handle /favicon.ico has not been defined.
0
 
farzanjCommented:
I have something like this:

perl -ne 'BEGIN {%h};/E\s+(.*)/;$h{$1}++; END{print "$_: $h{$_}\n" for keys(%h)}' filename

Open in new window


Problem is that the error messages are long and you did not mention any criteria where to chop them off.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.