2
  1. How to search through all the errors.zip as well as from errors.log files filter by "Error" string and sort by date?

  2. What about totals of errors?

requirement : here are 3 components are installed in my Linux server such as comp1,comp2 and comp3 . Each component has there own logs directory . Each logs directory contains below files Exception.log connection.log comp1.log as well as few *.zip files . I want to search them , order them based on date along with need to show the total number of error count.

error logs

2015-05-15 05:59:03,316 | 73002 | ERROR | JomaManagerThread RUNNING | Error clearing alarms to JOMA

Please let me know for additional information

8
  • Please provide example of your logs May 15, 2015 at 5:48
  • 2015-05-15 05:59:03,316 | 73002 | ERROR | JomaManagerThread RUNNING | Error clearing alarms to JOMA
    – user112232
    May 15, 2015 at 5:51
  • 1
    @RomeoNinov I think you missed the cat *.log when proposing your suggested edit ;-)
    – Anthon
    May 15, 2015 at 6:14
  • 1
    Yes, @Anthon :) And I usually prefer more visual style of structuring shell :) This is the reason I offer dedicated lines for *.log and sort May 15, 2015 at 6:21
  • 1
    @RomeoNinov I agree it tends to get messy rather quickly
    – Anthon
    May 15, 2015 at 6:23

1 Answer 1

1

Since you don't seem to need the filenames you can use -p to output the content of the zip files:

(for i in ./*.zip; do unzip -p "$i"; done; cat ./*.log) |
   grep -F ERROR | sort 

or if the files errors.zip are all over the place:

(find . -type f -name "*.zip" -exec unzip -p {} \;
 find . -type f -name "err*.log" -exec cat {} + ) |
   grep -F ERROR | sort

This does away with the zip file name and the particular content file name that unzip extracts, as well as the log file name. If you need that info I would write a python program for the task, that inserts the filename somewhere in each of the lines found (not before the date of course). You can use the standard zipfile module to process the contents of a zipfile without first extracting the files and have the program write to stdout for piping into sort

9
  • thanks for the reply Anthon . If i want to add multiple directory to this for loop shall it work .
    – user112232
    May 15, 2015 at 6:22
  • @user112232 yes you either do a *.zip */*.zip etc if the levels of subdirectories is limited, or else use find . -name "*.zip" -exec unzip -p {} \;" if the files are burried deep. For the logs the same applies.
    – Anthon
    May 15, 2015 at 6:31
  • i wrote the below command (for i in find . -name ".zip" -exec unzip -p {} \; do unzip -p "$i"; done; cat ".log") | grep -F ERROR| sort but getting this error "-bash: syntax error near unexpected token `done' "
    – user112232
    May 15, 2015 at 6:51
  • 1
    @user112232 I updated my answer. Next time please be more specific about details like the fact that you have no idea where the errors.zip files might be on the filesystem that makes it more easy to get the answers right.
    – Anthon
    May 15, 2015 at 6:56
  • Anthon , sorry for the inconvenience . let me clear my problem . There are 3 components are installed in my Linux server such as comp1,comp2 and comp3 . Each component has there own logs directory . each logs directory contains below files Exception.log,connection.log and comp1.log as well as few *.zip files . I want to search them , order them based on date along with need to show the total number of error count. Please let me know if you want some additional information.
    – user112232
    May 15, 2015 at 7:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .