Skip to content

Instantly share code, notes, and snippets.

@trchopan
Last active September 12, 2021 09:55
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 trchopan/ae82246e27b0455117d5b06ce7512b04 to your computer and use it in GitHub Desktop.
Save trchopan/ae82246e27b0455117d5b06ce7512b04 to your computer and use it in GitHub Desktop.
#!/bin/bash
PUBLIC_IP=<PUBLIC_IP>
PUBLIC_PORT=<PUBLIC_PORT>
AUTH="<USER_NAME>:<PASSWORD>"
PORTS=( 2222 3333 )
LOCAL_PORTS=( 22 3000 )
logdir="/home/ubuntu/chisel/log"
mkdir -p $logdir
while true; do
timestamp=$(date "+%Y%m%d-%H%M%S")
echo "=== Checking chisel clients ==="
for (( n=0; n<${#PORTS[@]}; n++ )); do
if [[ -z $(ps aux |grep chisel | grep ${PORTS[n]}) ]]; then
echo Starting chisel client ${PORTS[n]}
/home/ubuntu/go/bin/chisel client --auth "$AUTH" $PUBLIC_IP:$PUBLIC_PORT R:${PORTS[n]}:localhost:${LOCAL_PORTS[n]} > "$logdir/${PORTS[n]}-$timestamp" 2>&1 &
else
echo "chisel client found on ${PORTS[n]}"
fi
done
sleep 30
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment