I\'ve have to scripts:
#!/bin/bash netcat -lk -p 12345 | while read line do match=$(echo $line | grep -c \'Keep-Alive\') if [ $match -eq 1 ]; then
I have often experienced strange behaviour with nc or netcat. You should have a look at ncat it's almost the same tool but it behaves the same on all platforms (nc and netcat behave differently depending on distri, linux, BSD, Mac).
nc
netcat
ncat