Skip to content

Instantly share code, notes, and snippets.

@TomK
Created August 31, 2017 12:36
Show Gist options
  • Save TomK/277d582ebe902901f202c06e662b9336 to your computer and use it in GitHub Desktop.
Save TomK/277d582ebe902901f202c06e662b9336 to your computer and use it in GitHub Desktop.
Close all rabbit connections with state of 'closed'
#!/bin/bash
CONC=10
HOST="--host=rabbit.fortifi.uk"
echo "Listing connections..."
rabbitapi $HOST -f tsv -q list connections name state |grep closed |awk '{$NF=""; print $0}' > conn.txt
echo "Found $(wc -l conn.txt) closed connections"
I=0
while read -r name
do
echo "Closing $name"
rabbitapi $HOST -q close connection name="${name}" &
I=$(( $I + 1 ))
if [ $I -ge $CONC ]
then
wait
I=0
fi
done < conn.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment