Skip to content

Instantly share code, notes, and snippets.

@tstone2077
tstone2077 / startTunnel
Created October 16, 2019 15:07
Start an ssh dynamic tunnel for socks5 proxy
#!/bin/bash
#resp=$(aws ec2 describe-instances | jq '.Reservations[].Instances[] | select(.Tags[].Value=="$EC2_Name") | .InstanceId + " " + .State.Name'
EC2_Name=$1
resp=$(aws ec2 describe-instances | jq '.Reservations[].Instances[] | select(contains({Tags: [{Key: "Name"}, {Value: "$EC2_Name"}]}) ) | .InstanceId + " " + .State.Name' | sed 's/"//g')
respArray=($resp)
if test "${respArray[1]}" == "stopped"
then
echo "Starting EC3..."
aws ec2 start-instances --instance-ids ${respArray[0]}