Skip to content

Instantly share code, notes, and snippets.

@bb01100100
Created April 10, 2022 23:59
Show Gist options
  • Save bb01100100/d8a8b8a308fadcd73ee1d87c9144b4c2 to your computer and use it in GitHub Desktop.
Save bb01100100/d8a8b8a308fadcd73ee1d87c9144b4c2 to your computer and use it in GitHub Desktop.
Use bash's tcp pseudo device for fun and profit
#!/usr/bin/env bash
# We set up a file descriptor to redirect input/output from bash's tcp pseudodevice
# This allows us to, for example, call Zookeeper 4lws without needing netcat
# Works everywhere that bash works (proven on RHEL 7.x, AIX, MacOS bash 3.2)
ZKHOST="$1"
ZKPORT=2181
ZKCMD="$2"
if [ -z "$ZKCMD" ]; then
echo "Usage $0 zkhost [wchp wchc wchs stat srvr srst ruok envi dump crst cons conf]"
exit 1
fi
echo "Setting up file handle."
exec 3<>/dev/tcp/${ZKHOST}/${ZKPORT}
echo "Echo command to FH"
echo -e "${ZKCMD}" >&3
echo "Getting result..."
cat <&3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment