log-monitor
Monitor long-running task log files to detect completion or stalls using simple one-line shell commands. No scripts to install, no dependencies - just copy-paste commands for your shell.
Quick Start
Bash/Zsh - Exit when log stops growing for 2 minutes:
bash
last=-1; while true; do curr=$(wc -l <test.log 2>/dev/null || echo 0); if [ "$curr" = "$last" ]; then sleep 120 && [ "$curr" = "$(wc -l <test.log 2>/dev/null || echo 0)" ] && echo "STALE" && break; fi; last=$curr; sleep 10; done
PowerShell:
powershell
$last=-1; while($true){$curr=(Get-Content test.log -ErrorAction SilentlyContinue).Count; if($curr -eq $last){Start-Sleep 120; if($curr -eq (Get-Content test.log -ErrorAction SilentlyContinue).Count){Write-Host "STALE"; break}}; $last=$curr; Start-Sleep 10}
CMD:
cmd
@echo off & setlocal enabledelayedexpansion & set last=-1 & :loop & for /f %%i in ('type test.log ^| find /c /v "" 2^>nul') do set curr=%%i & if !last!==!curr! timeout /t 120 >nul && for /f %%i in ('type test.log ^| find /c /v "" 2^>nul') do if !curr!==%%i echo STALE & goto done & set last=!curr! & timeout /t 10 >nul & goto loop & :done
How It Works
The core concept: monitor line count growth. If no new lines are added for X minutes, the task is likely finished or stalled.
- •Count lines in log file every 10 seconds
- •Compare to previous count
- •If unchanged, wait 2 minutes (stale threshold)
- •If still unchanged, print "STALE" and exit
Full Examples
See references/examples.md for:
- •Verbose mode (showing line counts)
- •Timeout variants
- •Reusable shell functions
- •What NOT to do (bad patterns)
Customize
Change the variables in the one-liner:
- •
test.log→ your log file path - •
120→ stale threshold in seconds (2 min) - •
10→ check interval in seconds
Example - 5 minute stale, 30 second checks:
bash
last=-1; while true; do curr=$(wc -l <train.log 2>/dev/null || echo 0); if [ "$curr" = "$last" ]; then sleep 300 && [ "$curr" = "$(wc -l <train.log 2>/dev/null || echo 0)" ] && echo "STALE" && break; fi; last=$curr; sleep 30; done