Parse an accumulating log file and search for a specific string - How to?


I’m executing a command line from From my Powershell in the background. this command line creating a log file.

while the command line is running and the log file accordingly, I would like that my program will review the log file (which is increasing) and search for a specific word “Published” and when i “found” it starting another task in my program.

My question is, how should I do it? meaning, monitoring the log file while it’s increasing and searching for a specific string and then start a new process.

Please be aware, that the log file is accumulated - means it already contains that string from the previous execution, so i must ignore that information and take into account the new output from the current. maybe to monitor for the specific string in the last 5 lines in the log…or something like that.


Thanks in Advanced



There are several options you have.

You could read the log file periodically in a loop, search for the pattern you like and delete the part of the log file you already parsed. Or you “remember” until what line you already parsed the file and continue at this point on the next parse loop.

The command line you’re executing: Is it Powershell? If yes - you should show it. There might be a way to act even before you write the log file … :wink: :smiley:

Have you tried to search for a solution? I’m sure you’re not the first with such a requirement.

Hi, I’m beginner and i have some basic script that i put in production and it’s working now. What i did is just put whole text file in variable and search for match (get-comtent, if $content -match “text” {do somthing}). Nagios start script every 10 minutes and look for error, report it etc.

I’m interested in what u sad here: “There might be a way to act even before you write the log file …”

I’m looking for other ways to do this. Is there something that can be done through .net programing inside powershell … i read that something can be done with DCOM+ or similar?
Anything for me to read?