Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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"
share|improve this question

2 Answers 2

up vote 4 down vote accepted

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.

share|improve this answer
    
That's it, exactly like that! Thank you for answering! :) –  Nico Rodsevich Oct 11 '13 at 1:26

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)
share|improve this answer
    
I needed that, you understood me well. Thank you for answering! –  Nico Rodsevich Oct 11 '13 at 1:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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