This has 2 advantages:
1. It uses get_tcp_connections_for_ip() to check for leftover
connections, instead of custom code.
2. It checks for the timeout condition before sleeping. The current
code sleeps and then checks, so wastes a second.
Signed-off-by: Martin Schwenke <martin@meltin.net>
[ $_killcount -gt 0 ] || {
return;
}
+
_count=0
- while netstat -tn |egrep "^tcp.*[[:space:]]+$_IP:.*ESTABLISHED" > /dev/null; do
- sleep 1
- _count=`expr $_count + 1`
- [ $_count -gt 3 ] && {
+ while : ; do
+ if [ -z "$(get_tcp_connections_for_ip $_IP)" ] ; then
+ echo "killed $_killcount TCP connections to released IP $_IP"
+ return
+ fi
+
+ _count=$(($_count + 1))
+ if [ $_count -gt 3 ] ; then
echo "Timed out killing tcp connections for IP $_IP"
- return;
- }
+ return
+ fi
+
+ sleep 1
done
- echo "killed $_killcount TCP connections to released IP $_IP"
}
}