i have script running mirrors 2 directories , updates log file happens between 2 directories. want parse log file updates come in (while script running) , want these send me email of has changed, notification. - don't want notified same bit of info more once if possible?
i'm unsure on how go doing after reading through of command lists online.
tldr; really i'm looking when line added logfile, parse file updated line, without getting of other lines.
not strong powershell appreciated.
you can have powershell each new line comes in passing -wait
parameter get-content
. can pass foreach-object
scriptblock perform whatever operation need.
get-content $logfile -tail 0 -wait | foreach { "another line added: " + $_ }
the -tail n
argument causes get-content
last n lines; in case zero. causes skip in file, , pass newly added lines script block.
note: cmdlet continue running until cancel ctrl+c (or otherwise stop powershell process), makes better use in interactive prompt in script.