Skip to content

Instantly share code, notes, and snippets.

@sangjinhan
Last active September 15, 2023 14:04
Show Gist options
  • Save sangjinhan/636d7fe01ebb34f952a8 to your computer and use it in GitHub Desktop.
Save sangjinhan/636d7fe01ebb34f952a8 to your computer and use it in GitHub Desktop.
Shell Script for IPMI remote KVM console
#!/bin/bash
function cleanup {
# Remove JNLP file and SSH process
rm -f $HOST.jviewer.jnlp
kill $!
}
USAGE="Usage: $0 -p <SSH proxy host> <hostname> <username>"
while getopts ":p:" opt; do
case $opt in
p)
PROXY_HOST=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG"
exit 2
;;
esac
done
shift $((OPTIND-1))
if [ $# -ne 2 ]; then
echo $USAGE
exit 2
fi
HOST=$1
USER=$2
read -p "Password for $2@$1: " -s PASS
trap cleanup EXIT
if [ -z "$PROXY_HOST" ]; then
FRONTEND_HOST=$HOST
PORT=80
else
FRONTEND_HOST=localhost
PORT=8080
ssh -o ExitOnForwardFailure=yes -L $PORT:$HOST:80 -L 7578:$HOST:7578 $PROXY_HOST sleep 100000 &
sleep 1
fi
SESSION_URL="http://$FRONTEND_HOST:$PORT/rpc/WEBSES/create.asp"
JVIEWER_URL="http://$FRONTEND_HOST:$PORT/Java/jviewer.jnlp"
POST_MSG="WEBVAR_USERNAME=$USER&WEBVAR_PASSWORD=$PASS"
COOKIE=`curl -# --data $POST_MSG $SESSION_URL 2> /dev/null | grep SESSION_COOKIE | cut -d\' -f 4`
curl -# --cookie Cookie=SessionCookie=$COOKIE $JVIEWER_URL -o $HOST.jviewer.jnlp
echo "Did you know: You can connect to http://$FRONTEND_HOST:$PORT for the web console"
javaws -wait $HOST.jviewer.jnlp
@sangjinhan
Copy link
Author

  1. Only works with Intel boards (not with SuperMicro, for example)
  2. You must install JRE on your machine
  3. You will need to add the host to the Exception Site List, if not using a proxy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment