+_jrun() { # journal run. run args, log to journal, tail and grep the journal.
+ local pid pattern jr_pid sedscript cmd_name ended
+ ret=0
+ case $1 in
+ -p)
+ pattern="$2\|"
+ shift 2
+ ;;
+ esac
+ cmd_name=${1##*/}
+ systemd-cat -t "$cmd_name" "$@" 2>&1 &
+ pid=$!
+ sedscript="/$pattern$cmd_name/p;/^.{16}[^ ]+ $cmd_name\[$pid]: ([^ ]+ +)?exiting with status [0-9]+\$/q"
+ journalctl -S "4 seconds ago" -f |& sed -nr "$sedscript" 2>&1 &
+ jr_pid=$!
+ wait $pid 2>&1 || ret=$?
+ if (( $ret )); then
+ echo "$0: ERROR: $* returned $ret"
+ fi
+ jobs %'journalctl -S "4 seconds ago" -f' &>/dev/null
+ ended=false
+ # give it about 5 seconds to find the end of the log
+ for (( i=0; i<20; i++ )); do
+ if jobs %'journalctl -S "4 seconds ago" -f' &>/dev/null; then
+ sleep .3 2>&1
+ else
+ ended=true
+ break
+ fi
+ done
+ if ! $ended; then
+ kill $jr_pid 2>&1
+ fi