2

I would like to run ip monitor in the background and invoke a script whenever a new block of output is sent to stdout by ip monitor (or, ideally, if there are several new blocks sent within say 3 seconds, only invoke the script once)

I would like to use bash or python, but I'm open to other suggestions as well.

What is the best way to approach this?

maddingl
  • 197
  • 4
  • 20

1 Answers1

3

Using a while loop with read :

$ ip monitor all | while IFS= read -r line; do
    echo "CATCHED: $line";
    ./script "$line"
done

bash FAQ#1

Or using :

ip monitor all | xargs -n1 ./script
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223