Skip to content

Instantly share code, notes, and snippets.

@mie00
Last active September 6, 2018 14:08
Show Gist options
  • Save mie00/af5c579d9384b08743d9003c6074fffe to your computer and use it in GitHub Desktop.
Save mie00/af5c579d9384b08743d9003c6074fffe to your computer and use it in GitHub Desktop.
A script to dump data from and to your service
#!/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