Linux: repeatedly run a command to monitor output

If you need to repeatedly run a command and view the output changes over time then check out my script. I was watching a RAID array rebuild slowly and needed a way to see the progress over time.

Usage: [--delay 15] [--line 3] command

Run my_command every 15 seconds: --delay 15 'my_command | grep stuff'

Filter output to only line 2: --line 2 'ping -c 1'

Leave A Reply - 1 Reply
Matthew 2023-11-17 05:43pm - No Email - Logged IP:

There is a standard watch command (part of procps on linux, and its own watch package in homebrew on MacOS) which might be lighter weight than running a perl script.

It has options to highlight differences and to set the time between invocations, as well as some other nice flags.

It doesn't have a 'specific line number' option, though you could use awk (... | awk 'NR==12') / sed (.... | sed -n 12p) for that (though I can never remember those syntaxes, I end up looking them up when I need them :) )

All content licensed under the Creative Commons License