#!/bin/bash set -e set -f set -u set -o pipefail _safe_param_stdin() { tr -d '$`<>"%;)(&+'"'" } _main_server_watcher(){ inotifywait --event close_write --format '%f' --monitor "$dir" | \ while read -r line do # TODO: validate IP/hostname local target target="$(head -n 1 "$dir/$line" | _safe_param_stdin)" test -n "$target" xpra attach tcp://"$target":4648 & done } if [ "${SOURCED:-0}" != 1 ]; then readonly dir='/var/spool/doskast' _main_server_watcher "$@" fi