0

I feel like this should be answered somewhere but I am not able to find a good answer.

My requirement is that I need to scour last 3 months logs (several thousand files) for all exceptions, on Unix server.

so I need a command (or script) which should print, log file name, line number, exception first line, and then route that output > to a new file.

I want something I can run in the background and check after that process is completed.

I can then analyze that file for all the frequent exceptions and can concentrate on the most occurring ones.

Thanks for the help.

1 Answers1

0

I think this might help you,

To delete old files you can directly use find like below,

find <PATH> -type f -mtime -90 -exec rm {} \;

Please confirm the folder before running the command as it also has rm

now the trick is the mtime option of find,

mtime is modified time, the above command will return all the files that are modified in the last 90 days, (if you give +90 it will return all files modified more than 90 days).

If you want to grep use the find and pipe it to grep like below,

find <PATH> -type f -mtime -90 | xargs grep -in <PATTERN> > output.log
ArigatoManga
  • 594
  • 5
  • 23