From 47e5868451a21de18acc7d44604388de7ab56c34 Mon Sep 17 00:00:00 2001 From: Gilles Grandou Date: Fri, 10 Sep 2021 10:45:00 +0200 Subject: [PATCH] run: add log command --- run | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/run b/run index f447606..c08c2e9 100755 --- a/run +++ b/run @@ -2,6 +2,7 @@ dev=/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A500DA2H-if00-port0 rundir=$(realpath $(dirname $0)) +session="tic2mqtt" cmd="" quiet="" @@ -12,16 +13,17 @@ while [ $# -gt 0 ]; do stop) cmd=$1;; restart) cmd=$1;; status) cmd=$1;; + log) cmd=$1;; -q) quiet=$1;; --quiet) quiet=$1;; - *) echo "usage: $0 [start|stop|restart|status] [-q|--quiet]" + *) echo "usage: $0 [start|stop|restart|status|log] [-q|--quiet]" exit 1 ;; esac shift done -is_running=$(tmux has -t tic2mqtt 2> /dev/null && echo yes) +is_running=$(tmux has -t $session 2> /dev/null && echo yes) case "$cmd" in start) @@ -31,7 +33,7 @@ case "$cmd" in fi make -s test -z $quiet && echo "starting tic2mqtt" - tmux new -s tic2mqtt -d "./tic2mqtt -a -t $dev -h doctor -v" + tmux new -s $session -d "./tic2mqtt -a -t $dev -h doctor -v" test -z $quiet && tmux ls ;; stop) @@ -40,7 +42,7 @@ case "$cmd" in exit 0 fi test -z $quiet && echo "killing tic2mqtt" - tmux kill-session -t tic2mqtt + tmux kill-session -t $session ;; restart) $0 $quiet stop @@ -48,7 +50,16 @@ case "$cmd" in ;; status) if [ -n "$is_running" ]; then - tmux ls | grep tic2mqtt + tmux ls | grep $session + else + echo "no tic2mqtt running" + fi + ;; + log) + if [ -n "$is_running" ]; then + tmux capture -b $session -p -S - | head -15 + echo "[...]" + tmux capture -b $session -p -E - else echo "no tic2mqtt running" fi