Last active
September 6, 2018 14:08
-
-
Save mie00/af5c579d9384b08743d9003c6074fffe to your computer and use it in GitHub Desktop.
A script to dump data from and to your service
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 | |
# Usage: ./my-service --listen=127.0.0.1:`mon 8080` | |
PORT=$(( ((RANDOM<<15)|RANDOM) % 63001 + 2000 )) | |
echo "$PORT" | |
socat -v TCP4-LISTEN:"$1",bind=127.0.0.1,reuseaddr,fork TCP4:"${2:-127.0.0.1}":$PORT >&2 & ! | |
PID=$! | |
bash -c 'sleep 20; while nc -z '"${2:-127.0.0.1}"' '"$PORT"' ; do sleep 1; done; kill '"$PID" >&2 & ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment