Skip to content

Instantly share code, notes, and snippets.

@pietern
Created May 3, 2012 18:04
Show Gist options
  • Save pietern/2587670 to your computer and use it in GitHub Desktop.
Save pietern/2587670 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
set -x
path=$(mktemp -d)
rd=$path/rd
wr=$path/wr
mkfifo $rd
mkfifo $wr
nc $@ < $rd | grep --line-buffered "^+PONG" > $wr &
(
# Wait for PONG in the background
(
read foo
) < $wr &
# Send stdin and sentinel PING
cat
printf "PING\r\n"
# Wait for PONG (before closing $rd, which terminates `nc`)
wait
) > $rd
# Clean up
rm -rf $path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment