Created
October 21, 2021 13:19
-
-
Save csobankesmarki/61f883ed8a96da0276634fe84c92ee68 to your computer and use it in GitHub Desktop.
Read and write UNIX sockets from BASH
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 | |
while true; do | |
SKT_PATH=/var/run/mysock.sock | |
rm $SKT_PATH | |
INPUT=$(mktemp -u) | |
mkfifo -m 600 "$INPUT" | |
OUTPUT=$(mktemp -u) | |
mkfifo -m 600 "$OUTPUT" | |
(cat "$INPUT" | nc -U "$SKT_PATH" > "$OUTPUT") & | |
NCPID=$! | |
exec 4>"$INPUT" | |
exec 5<"$OUTPUT" | |
echo "$POST_LINE" >&4 | |
read -u 5 -r RESPONSE; | |
echo "Response: '$RESPONSE'" | |
done | |
kill $NCPID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment