3

there are commands like

iwevent

or

tcpdump -n src host x.x.x.x

that send to the stdout some lines when something happens. Is there any form of running some command inmmediatly after a line is printed. Ex:

iwevent | echo "Wireless event happened"
4

Just read stdin in a loop

iwevent | while IFS= read -r line; do
    echo "[$(date "+%F %T")] - $line"
done

Depending on what you do in the loop body, you might want

while IFS= read -r line; do
    echo "[$(date "+%F %T")] - $line"
done < <(iwevent)

That avoids the implicit subshell effects of using a pipeline.

  • That's it, exactly like that! Thank you for answering! :) – Nico Rodsevich Oct 11 '13 at 1:26
3

Not sure I get what you mean, but something in the direction of this?

while IFS= read -r line; do
    printf "%s\n%s\n" "$line" "Yohooo! One more package."
done < <(tcpdump -i any -nS)
  • I needed that, you understood me well. Thank you for answering! – Nico Rodsevich Oct 11 '13 at 1:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.