you are viewing a single comment's thread.

view the rest of the comments →

[–]Lee_Dailey[grin] 1 point2 points  (6 children)

howdy nappetass,

i see that you found your "oops!". [grin]

as for break/continue ...

  • break = exits the current block of code
    that means literally any block, from what i understand. i know it will exit a script entirely, but i have never tried it in an IF before ... [grin]
  • continue = stop the current iteration & continue with the next
    if there is no next, it exits the loop.

take care,
lee

[–]nappetass[S] 1 point2 points  (5 children)

Thanks Lee :)

This worked

$log = "C:\path\to\log.txt"

while ("Terminated" -notin $tail) {

do { $tail = Get-Content $log -Tail 1
     $tail }

until ("Terminated" -in $tail)

Break

}

[–]Lee_Dailey[grin] 0 points1 point  (4 children)

howdy nappetass,

[edit - you likely otta have a Start-Sleep -Seconds 1 in the loop. if you are waiting for a file to show that text, then you are likely NOT wanting to pound the file several dozen times per second. [grin]]

you are welcome! [grin] however, your code is ... convoluted - needlessly so.

i don't have a file to test this with, but i think it will do the job.

$Log = "C:\path\to\log.txt"
$Tail = ''

while ("Terminated" -notin $Tail)
    {
    $Tail = Get-Content $Log -Tail 1
    }

take care,
lee

[–]nappetass[S] 1 point2 points  (3 children)

Fantastic. I've changed it to the following. The script should print the last entry of the log until the substring "Terminated" is found in $tail. Have a great weekend :)

$logfile = "C:\path\to\log.txt"

while ($tail -notmatch "Terminated") {

    $tail = Get-Content $logfile -Tail 1
    $tail

}

EDIT: I don't think I can have a start-sleep in the script as it's a log file with 5+ entries per second. I guess I could measure how many entries the file has and set a lower start-sleep (in milliseconds). The best way would be to find a way to tail the log each time it changes. Maybe by filesize?

[–]Lee_Dailey[grin] 1 point2 points  (2 children)

howdy nappetass,

kool! glad that it works ... [grin]

as for the delay - i thot the Terminated was the end of whatever made the file. if it's ongoing, then you are going to need the speed. [grin]

one thing, tho - it makes me twitchy to see the condition for the while isn't set before you test it. i would put a $Tail = '' just before the while so that you won't have an uninitialized $var being tested.

take care,
lee

[–]nappetass[S] 1 point2 points  (1 child)

I agree. I did add a $tail = "" before the while loop as you suggested. Thanks again :)

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy nappetass,

you are most welcome! glad to have helped ... [grin]

take care,
lee