about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2020-04-30 15:45:19 -0500
committerCase Duckworth2020-04-30 15:45:19 -0500
commit780fffe26863d141f69b2a4daa6aa3d8d463883a (patch)
tree2c3ebcfcce7c9bda3eefa2129a107c6c8757c205
parentUpdate style (diff)
downloadmrgrctrnl-780fffe26863d141f69b2a4daa6aa3d8d463883a.tar.gz
mrgrctrnl-780fffe26863d141f69b2a4daa6aa3d8d463883a.zip
Break on failure
-rwxr-xr-xmrgrctrnl28
1 files changed, 18 insertions, 10 deletions
diff --git a/mrgrctrnl b/mrgrctrnl index d51be58..af29269 100755 --- a/mrgrctrnl +++ b/mrgrctrnl
@@ -35,12 +35,15 @@ die() {
35 35
36demolish_tunnels() { 36demolish_tunnels() {
37 printf '%s...' "Demolishing tunnels" 37 printf '%s...' "Demolishing tunnels"
38 while read -r pid; do 38 if [ -f "$pidf" ]; then
39 [ -z "$pid" ] && continue 39 while read -r pid; do
40 kill "$pid" 2>/dev/null 40 [ -z "$pid" ] && continue
41 done <"$pidf" 41 kill "$pid" 2>/dev/null
42 rm "$pidf" 42 done <"$pidf"
43 sleep 3 43 rm "$pidf"
44 else
45 pkill -x ssh
46 fi
44 printf '%s.\n' "Done" 47 printf '%s.\n' "Done"
45} 48}
46 49
@@ -48,7 +51,7 @@ config="${XDG_CONFIG_HOME:=$HOME/.config}/mrgrctrnl/config"
48pidf=/tmp/mrgrctrnl.pid 51pidf=/tmp/mrgrctrnl.pid
49dry_run=false 52dry_run=false
50 53
51while getopts hc:dk opt; do 54while getopts hc:dkr opt; do
52 case "$opt" in 55 case "$opt" in
53 h) usage ;; 56 h) usage ;;
54 c) config="$OPTARG" ;; 57 c) config="$OPTARG" ;;
@@ -58,6 +61,11 @@ while getopts hc:dk opt; do
58 pkill -x mrgrctrnl 61 pkill -x mrgrctrnl
59 exit 62 exit
60 ;; 63 ;;
64 r)
65 demolish_tunnels
66 exec mrgrctrnl
67 exit
68 ;;
61 \?) usage 2 ;; 69 \?) usage 2 ;;
62 *) usage 2 ;; 70 *) usage 2 ;;
63 esac 71 esac
@@ -83,11 +91,11 @@ awk '{sub(/#.*$/,"");print}' "$config" |
83 91
84 echo ssh "$@" 92 echo ssh "$@"
85 93
94 touch "$pidf"
86 "$dry_run" || { 95 "$dry_run" || {
87 while :; do 96 while [ -f "$pidf" ]; do
88 ssh "$@" 97 ssh "$@" || break
89 echo "$!" >>"$pidf" 98 echo "$!" >>"$pidf"
90 sleep 5
91 done & 99 done &
92 } 100 }
93 done 101 done