Skip to content

Instantly share code, notes, and snippets.

@amcginlay
Last active June 3, 2020 11:37
Show Gist options
  • Save amcginlay/731d2f2fe77fc9cb56509502bb17ffb4 to your computer and use it in GitHub Desktop.
Save amcginlay/731d2f2fe77fc9cb56509502bb17ffb4 to your computer and use it in GitHub Desktop.
socat server user data - example request: curl localhost/3
# inspired by https://jameshfisher.com/2018/12/31/how-to-make-a-webserver-with-netcat-nc/
#!/bin/bash
yum install -y socat
socat TCP4-LISTEN:${PORT:-80},fork SYSTEM:' \
read -r line \
read -r _ workload _ <<< "$line" \
workload=${workload:1}
[ ! -z "$workload" ] && timeout $workload yes > /dev/null \
echo HTTP/1.0 200 \
echo Content-Type\: text/plain \
echo \
echo Response from $(hostname) with ${workload:-0} secs workload at $(date '+%s.%N')'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment