forked from MultiPoolMiner/MultiPoolMiner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Reader.ps1
20 lines (14 loc) · 1.19 KB
/
Reader.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
param([String]$Log = ".\.txt", [String]$Sort = "", [Switch]$QuickStart)
Set-Location (Split-Path $MyInvocation.MyCommand.Path)
$Active = @()
while ($true) {
Compare-Object @(Get-Job -ErrorAction Ignore | Select-Object -ExpandProperty Name) @(Get-ChildItem ".\Logs" -ErrorAction Ignore | Where-Object {(-not $QuickStart) -or ((Get-Date) - $_.LastWriteTime).TotalMinutes -le 1} | Select-Object -ExpandProperty Name) |
Sort-Object {$_.InputObject -replace $Sort} |
Where-Object InputObject -match $Log |
Where-Object SideIndicator -EQ "=>" |
ForEach-Object {$Active += @{Id = (Start-Job ([ScriptBlock]::Create("Get-Content '$(Convert-Path ".\Logs\$($_.InputObject)")' -Wait$(if($QuickStart){" -Tail 1000"}) -Encoding UTF8")) -Name $_.InputObject).Id; Time = (Get-Date).ToUniversalTime()}}
Start-Sleep 1
Get-Job | Where-Object {$_ | Receive-Job -Keep; $Active += @{Id = $_.Id; Time = (Get-Date).ToUniversalTime()}} | Select-Object -First 1 | Receive-Job | Where-Object {$_}
$Active = @($Active | Where-Object Time -ge (Get-Date).ToUniversalTime().AddMinutes(-10))
Get-Job | Where-Object {-not ($Active | Where-Object Id -EQ $_.Id)} | Remove-Job -Force
}