diff options
Diffstat (limited to 'teaqueue-client')
-rwxr-xr-x | teaqueue-client | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/teaqueue-client b/teaqueue-client new file mode 100755 index 0000000..c52d01e --- /dev/null +++ b/teaqueue-client @@ -0,0 +1,47 @@ +#!/bin/sh + +set -eu + +# default options +host="127.0.0.1" +port=1340 +retry_timeout=10 + +usage() +{ + cat <<EOF +Usage: $0 [OPTIONS...] command [args...] + +Connects to a teaqueue-server and call "command" with a line in stdin. + +Options: + -h, --help show usage + -H, --host what teaqueue-server host (default: 127.0.0.1) + -p, --port what port to use (default: 1340) +EOF +} + +# arg parsing +TEMP=$(getopt -o hH:p: --long help,host,port -n teaqueue-client -- "$@") +if [ $? != 0 ]; then echo "Terminating..." >&2; exit 1; fi +eval set -- "$TEMP" +while true; do + case "$1" in + -h|--help) usage; exit 0;; + -H|--host) host="$2"; shift 2;; + -p|--port) port="$2"; shift 2;; + --) shift; break;; + *) echo "Arguments parsing error" >&2; exit 1;; + esac +done + +if test $# -lt 1; then + echo "You must put a command to call" >&2; exit 1 +fi + +set +e + +while true; do + while ! nc -q0 "$host" "$port"; do sleep $retry_timeout; done | "$@" + sleep 1 +done |