Skip to content

Instantly share code, notes, and snippets.

@pharaujo
Last active January 8, 2018 15:00
Show Gist options
  • Save pharaujo/873bb53704367129b816a6a37db1cc1c to your computer and use it in GitHub Desktop.
Save pharaujo/873bb53704367129b816a6a37db1cc1c to your computer and use it in GitHub Desktop.
Pure bash OpenTSP site feed client (for debugging)
#!/usr/bin/env bash
#
# Accepts OpenTSDB line protocol connections
# Responds to `version` requests
# Outputs everything else to stdout
tsdb_connector() { nc -l -k 0 4545 ; }
coproc TSDB { tsdb_connector; }
while IFS='' read -ru ${TSDB[0]} line; do
if [ "$line" == "version" ]; then
echo "Built on <unknown> (bash_tsp_client)" >&${TSDB[1]}
else
echo "$line"
fi
done
# 1-liner:
# ( tsdb_connector() { nc -l -k 0 4545 ; } ; coproc TSDB { tsdb_connector; } ; while IFS='' read -ru ${TSDB[0]} line; do if [ "$line" == "version" ]; then echo "Built on <unknown> (bash_tsp_client)" >&${TSDB[1]} ; else echo "$line" ; fi; done; )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment