Created
October 16, 2019 15:07
-
-
Save tstone2077/75d7cae07241757eca811648cf185df1 to your computer and use it in GitHub Desktop.
Start an ssh dynamic tunnel for socks5 proxy
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 | |
#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]} | |
not_running=0 | |
while test $not_running -eq 0 | |
do | |
newResp=$(aws ec2 describe-instances | jq '.Reservations[].Instances[] | select(.Tags[].Value=="$EC2_Name") | .State.Name' | sed 's/"//g') | |
echo $newResp | |
if test "$newResp" == "running" | |
then | |
not_running=1 | |
fi | |
done | |
fi | |
IP=$(aws ec2 describe-instances --instance-ids ${respArray[0]} | jq '.Reservations[].Instances[].NetworkInterfaces[].Association.PublicIp' | sed 's/"//g') | |
echo "Proxy is running on localhost:2020 ..." | |
ssh -N -D 2020 ec2-user@$IP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment