Python Script for Searching Log Files

Environment: Python 2.7 (Should run fine in PY3 as well after ‘fixing’ print statements)

This script was designed for searching interface log files for list of keywords. If ran as a standalone script, amend argumens highlighted in lines 29-31:

keywords – comma separated string with list of keywords we are searching for. Note that space symbol is also count, so, for example, keywords = ”’123, 345”’ means that you are interested in ‘123’ and ‘ 345’ (space and then digits ‘345’) entries

search_dir – root directory where the search starts, search is recursive

date_since – use this argument if you want to limit search to files that have been modified after specific date, so, for example, with date_since = “01/11/2012” only files modified on or after the 1st of Nov 2012 will be searched. date_since has to be entered in dd/mm/yyyy format, if not provided (or mistyped) – script runs without modified date parameter.

You may want to amend condition for file format in line 52, the current version searches only in files with extension ‘.log

Share on LinkedInShare on Google+Tweet about this on TwitterShare on FacebookShare on Reddit