From 780fffe26863d141f69b2a4daa6aa3d8d463883a Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 30 Apr 2020 15:45:19 -0500 Subject: Break on failure --- mrgrctrnl | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/mrgrctrnl b/mrgrctrnl index d51be58..af29269 100755 --- a/mrgrctrnl +++ b/mrgrctrnl @@ -35,12 +35,15 @@ die() { demolish_tunnels() { printf '%s...' "Demolishing tunnels" - while read -r pid; do - [ -z "$pid" ] && continue - kill "$pid" 2>/dev/null - done <"$pidf" - rm "$pidf" - sleep 3 + if [ -f "$pidf" ]; then + while read -r pid; do + [ -z "$pid" ] && continue + kill "$pid" 2>/dev/null + done <"$pidf" + rm "$pidf" + else + pkill -x ssh + fi printf '%s.\n' "Done" } @@ -48,7 +51,7 @@ config="${XDG_CONFIG_HOME:=$HOME/.config}/mrgrctrnl/config" pidf=/tmp/mrgrctrnl.pid dry_run=false -while getopts hc:dk opt; do +while getopts hc:dkr opt; do case "$opt" in h) usage ;; c) config="$OPTARG" ;; @@ -58,6 +61,11 @@ while getopts hc:dk opt; do pkill -x mrgrctrnl exit ;; + r) + demolish_tunnels + exec mrgrctrnl + exit + ;; \?) usage 2 ;; *) usage 2 ;; esac @@ -83,11 +91,11 @@ awk '{sub(/#.*$/,"");print}' "$config" | echo ssh "$@" + touch "$pidf" "$dry_run" || { - while :; do - ssh "$@" + while [ -f "$pidf" ]; do + ssh "$@" || break echo "$!" >>"$pidf" - sleep 5 done & } done -- cgit 1.4.1-21-gabe81