Skip to content

Instantly share code, notes, and snippets.

@EnigmaCurry
Created February 10, 2015 02:27
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EnigmaCurry/bdd9fd28d7a73fe52eb4 to your computer and use it in GitHub Desktop.
Save EnigmaCurry/bdd9fd28d7a73fe52eb4 to your computer and use it in GitHub Desktop.
Bitcoin remote RPC client
#!/bin/bash
# Remote bitcoind RPC client through SSH tunnel
#
# If you have a remote bitcoind you'd like to query it's RPC interface
# from, this script will help you maintain the SSH tunnel to do so.
#
# Set REMOTE_HOST to the user@server your remote bitcoind is running on
# Set LOCAL_FORWARD_PORT to the port you want to run the tunnel on
# Set the RPC_PASSWORD to the rpc password bitcoind is set to use.
# Install bitcoind locally, so that you can use it's query interface.
#
# The first run will setup the SSH tunnel, and leave it running.
# Subsequent runs will be fast.
REMOTE_HOST=your_user@your_server
LOCAL_FORWARD_PORT=18332
RPC_PASSWORD=YOUR_RPC_PASSWORD_SET_IN_BITCOIN.CONF
# Check if the tunnel is already open:
port_open=$(netstat -lnt | grep 127.0.0.1:$LOCAL_FORWARD_PORT | wc -l)
if [ $port_open -lt 1 ]
then
echo "Creating port forward..."
ssh -N $REMOTE_HOST -L $LOCAL_FORWARD_PORT:localhost:8332 &
sleep 5
# Check if the tunnel was created successfully:
port_open=$(netstat -lnt | grep 127.0.0.1:$LOCAL_FORWARD_PORT | wc -l)
if [ $port_open -lt 1 ]
then
echo "Could not create port forward"
exit 1
fi
fi
bitcoind -rpcport=$LOCAL_FORWARD_PORT -rpcpassword=$RPC_PASSWORD $*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment