Created
December 8, 2025 02:58
-
-
Save link89/e69199ef9bc5327ebf9ae8828fcc4d28 to your computer and use it in GitHub Desktop.
A crontab script to test and keep tcp tunnel alive.
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
| #!/bin/bash | |
| TARGET_LIST=( | |
| "127.0.0.1 22001" | |
| "127.0.0.1 22002" | |
| "127.0.0.1 22003" | |
| ) | |
| LOG_FILE=~/log/tcp_keep_alive.log | |
| TIMEOUT_BIN=/usr/bin/timeout | |
| NC_BIN=/usr/bin/nc | |
| TIMEOUT_NC="1" | |
| TIMEOUT_CMD="5" | |
| mkdir -p ~/log | |
| for TARGET_ENTRY in "${TARGET_LIST[@]}"; do | |
| if ! $TIMEOUT_BIN $TIMEOUT_CMD $NC_BIN -z -w $TIMEOUT_NC $TARGET_ENTRY 2>&1 > /dev/null; then | |
| echo "$(date "+%Y-%m-%d %H:%M:%S") [Error]:fail to connect to $TARGET_ENTRY" >> $LOG_FILE | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment