Skip to content

Instantly share code, notes, and snippets.

@miguelarauj1o
Forked from robertoaloi/kill-erlang-node.sh
Created December 14, 2016 03:33
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 miguelarauj1o/bb1630141b2c70fd444c2b9d1711fa74 to your computer and use it in GitHub Desktop.
Save miguelarauj1o/bb1630141b2c70fd444c2b9d1711fa74 to your computer and use it in GitHub Desktop.
Kill an Erlang process by node name
#!/usr/bin/env bash
# Kill an Erlang process by node name
#
# e.g.: kill-erlang-node kred
# Check usage
if [ -z "$1" ]; then
echo "Usage: `basename $0` NODE_NAME"
exit 1
fi
# Fetch input parameters
NAME="$1"
# Kill the Erlang process corresponding to a given node name
port=`epmd -names | awk -v name=$NAME '$2==name {print $5}'`
if [ -z "$port" ]; then
echo "ERROR: Node name not found: $NAME"
exit 1
else
pid=`lsof -i TCP:$port -s TCP:LISTEN | tail -n +2 | awk '{print $2}'`
kill $pid
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment