Created
May 18, 2022 14:59
-
-
Save FATESAIKOU/2089ee6e372de30f8728a73deb80920d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/env sh | |
| CHECK_INV=600 | |
| REMOTE_USER='remote_user' | |
| REMOTE_PORT=22 | |
| REMOTE_HOST='example.com' | |
| DST_PORT=22 | |
| SRC_PORT=2222 | |
| PRIVATE_KEY='/home/local_user/.ssh/id_rsa' | |
| SSH_CMD="ssh -NfR "$SRC_PORT:localhost:$DST_PORT" -i $PRIVATE_KEY $REMOTE_USER@$REMOTE_HOST"; | |
| SSH_CHK="ssh -p $REMOTE_PORT -i $PRIVATE_KEY $REMOTE_USER@$REMOTE_HOST \"netstat -an | egrep 'tcp.*:$SRC_PORT.*LISTEN'\" > /dev/null 2>&1"; | |
| while true; | |
| do | |
| $SSH_CHK; | |
| if [ $? -ne 0 ]; | |
| then | |
| killall -9 ssh; | |
| $SSH_CMD; | |
| fi | |
| sleep $CHECK_INV; | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment