Last active
August 29, 2015 14:14
-
-
Save lpgauth/5df2c97f356073b0e3cf to your computer and use it in GitHub Desktop.
Bash script to open remote erlang shell on firewalled box
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -ne 3 ]; then | |
echo "Usage: $0 hostname name cookie"; | |
exit 1; | |
fi | |
HOST="$1" | |
NAME="$2" | |
COOKIE="$3" | |
CONTROL_PATH="remote-shell" | |
LOCAL_EPMD_PORT=$(($RANDOM + 1024)) | |
LOCAL_SERVICE_PORT=$(($RANDOM + 1024)) | |
REMOTE_EPMD_PORT=4369 | |
REMOTE_SERVICE_PORT=$(ssh $HOST "epmd -names" | grep $NAME | awk '{print $5}') | |
ssh -M -S $CONTROL_PATH \ | |
-fNTL $LOCAL_EPMD_PORT:localhost:$REMOTE_EPMD_PORT \ | |
-fNTR $LOCAL_SERVICE_PORT:localhost:$LOCAL_SERVICE_PORT \ | |
-fNTL $REMOTE_SERVICE_PORT:localhost:$REMOTE_SERVICE_PORT $HOST | |
export ERL_EPMD_PORT=$LOCAL_EPMD_PORT | |
erl -name remote@127.0.0.1 \ | |
-kernel inet_dist_listen_min $LOCAL_SERVICE_PORT inet_dist_listen_max $LOCAL_SERVICE_PORT \ | |
-setcookie $COOKIE \ | |
-connect_all false | |
ssh -S $CONTROL_PATH -O exit $HOST |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment