#!/bin/sh -ue exec 4>&1 1>&2 usage() { cat </dev/null; then echo "lock $spool_dir/lock exists. (PIO_NOLOCK=$PIO_NOLOCK)" [ -z "${PIO_NOLOCK+isset}" ] && exit 1 else echo locked "$spool_dir/lock" fi cleanup() { trap '' TERM [ -n "$pid" ] && kill $pid echo "releasing $spool_dir/lock" rm -f "$spool_dir/lock" || true exit 0 } trap 'cleanup' TERM INT echo "$PIO_TOKEN" echo "$URL" count=0 while true; do pid="" date=$(date +"%Y%m%d%H%M%S") out="$spool_dir/$date.$count" touch "$spool" ws-stdio -a "0.0.0.0:$PORT" -t "$PIO_TOKEN" -- /bin/sh -x -c 'tail -f $spool' >&4 & pid=$! wait $pid mv "$spool" "$out" #warm: potential race condition - irrelevant while not ACKing in ws-stdio & browser app [ -s "$out" ] || rm "$out" count=$((count + 1)) done cleanup