I have a little bit of bash (see bottom) that basically checks to see if any box is pingable on the LAN. But with a trick: it'll quit/return the instant it gets a single reply. That's so my script doesn't have to wait for nmap to finish (which can take a minute vs maybe 1 sec for the first computer to respond).
It works great. One problem though... on one box only, sometimes (not always) I'll get a:
grep: write error: Broken pipe
in the output. I would like to suppress that error.
I ran bash with -x and the grep error appears in the debug output after the grep -q RCVD line... however I'm not sure that's not a red herring as the entire stanza may be counted as one line for the debug? And I fail to see how there can be a write error on that part of the pipe -- there's nothing it's piping to! A read error, sure. But write?
Yes, the kill makes huge swathes of the pipe just "go away", and maybe that's part of it. But I'm trying to redirect most 2>&1's as you can see.
I don't need to solve the "problem" of pipes disappearing, I just want it to shut up. I also want to solve it without putting the meat of the code into a separate script (that seems like cheating). Any ideas?
sint=192.168.100
timeout 20 bash -c \ " \ (nmap -ddd -vvv --send-ip \ --host-timeout 5s --max-rtt-timeout 1s --initial-rtt-timeout 500ms \ --max-retries 1 -S $sint.1 -sn -PE $sint.2 $sint.100-254 2>&1 & \ echo $! >&3) \ 3>pidnmap \ | grep --line-buffered -P 'RCVD.{0,30}?ICMP.{0,60}?Echo reply' \ | (head -1 && /bin/kill $(<pidnmap) >/dev/null 2>&1) \ " \ |grep -q RCVD || { # do some network-restart stuff }