Skip to content

Instantly share code, notes, and snippets.

@reines
Last active August 29, 2015 14:09
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 reines/a2f14e10834bda4e3cd9 to your computer and use it in GitHub Desktop.
Save reines/a2f14e10834bda4e3cd9 to your computer and use it in GitHub Desktop.
jConsole over SSH
#!/bin/bash -e
if [ $# -lt 1 ]; then
echo "Usage: $0 <remote host>"
exit 1
fi
HOST="$1"
PROXY_PORT=$((((RANDOM<<15)|RANDOM) % 63001 + 2000))
JAVA_VERSION=1.7
JAVA_PATH=`/usr/libexec/java_home -v ${JAVA_VERSION}`
ssh -v -N -D${PROXY_PORT} "${HOST}" &
SSH_PID=$!
function finish {
kill ${SSH_PID}
}
trap finish EXIT
${JAVA_PATH}/bin/jconsole -J-DsocksProxyHost=localhost -J-DsocksProxyPort=${PROXY_PORT}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment