From d5f22f1a49c43d65c252bef1141895446da5c388 Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Wed, 8 Nov 2023 12:46:39 +0100 Subject: [PATCH] mqtt_smarthome in tmux --- mqtt_smarthome | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mqtt_smarthome b/mqtt_smarthome index 473cc9c..360f34c 100755 --- a/mqtt_smarthome +++ b/mqtt_smarthome @@ -1,4 +1,16 @@ #!/bin/sh clear -/opt/mqtt_sniffer/venv/bin/python /opt/mqtt_sniffer/mqtt_sniffer.py -f mqtt.home + +#!/bin/sh +# + +for s in $(tmux list-sessions -F '#{session_name}'); do + p=$(tmux list-panes -F '#{pane_tty}' -t "$s") + if [ "$p" = "$(tty)" ]; then + # Session already running + exit 0 + fi +done + +tmux attach-session -t mqtt_smarthome || tmux new-session -s mqtt_smarthome "/opt/mqtt_sniffer/venv/bin/python /opt/mqtt_sniffer/mqtt_sniffer.py -f mqtt.home"