I use the following command to send pinging IP's to a script:
sudo tcpdump -ne -l -i eth0 icmp and icmp[icmptype]=icmp-echo \
| cut -d " " -f 10 | xargs -L2 ./pong.sh
Unfortunately this gives me:
tcpdump: Unable to write output: Broken pipe
To dissect my commands:
Output the ping's from the traffic:
sudo tcpdump -ne -l -i eth0 icmp and icmp[icmptype]=icmp-echoOutput:
11:55:58.812177 IP xxxxxxx > 127.0.0.1: ICMP echo request, id 50776, seq 761, length 64This will get the IP's from the tcpdump output:
cut -d " " -f 10 # output: 127.0.0.1Get the output to the script:
xargs -L2 ./pong.shThis will mimic the following example command:
./pong.sh 127.0.0.1
The strange thing is that the commands work seperate (on their own)...
I tried debugging it but I have no experience with debugging pipes. I checked the commands but they seem fine.
It would seem that's
cutstdio buffering is interfering here, i.e. replace| xargs ...by| catin your cmdline to find out.Fwiw below cmdline wfm (pipe straight to
xargsthen use the shell itself to get the nth arg), note btw the extratcpdumpargs :-c10(just to limit to 10pkts, then show the 10/2 lines) and-Q in(only inbound pkts):