Skip to content

Instantly share code, notes, and snippets.

@menzow
Created May 7, 2018 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save menzow/b6cf565964aa95f2b1d1fa69ee7a12ab to your computer and use it in GitHub Desktop.
Save menzow/b6cf565964aa95f2b1d1fa69ee7a12ab to your computer and use it in GitHub Desktop.
Run slurp and grep time_wait sockets. Works on both linux as macos.
#!/bin/bash
function socket_count(){
if [[ "$OSTYPE" == "darwin"* ]]; then
sysctl net.inet.tcp.tw_pcbcount | awk '{ print $2 }'
else
netstat -n | grep -i 80| grep -i time_wait | wc -l
fi
}
printf "Starting slurp..." && (slurp keyword -t example,example1,example2 &>/dev/null &)
sockets="$()"
while [[ "$(socket_count)" -le $sockets ]]; do
printf '.'
sleep 1
done
echo ' done.'
for i in {0..5}; do (echo "time_wait sockets: $(socket_count)" && sleep 1); done
sockets=$(socket_count)
printf "Stoping slurp..." && (killall slurp)
while [ "$(socket_count)" -ge $sockets ]; do
printf '.'
sleep 1
done
echo ' done.'
for i in {0..10}; do (echo "time_wait sockets: $(socket_count)" && sleep 1); done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment