From 1f5c56d2de26395ebaec3f8086004b0387273ced Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 12 Apr 2020 12:13:19 -0500 Subject: Add dry_run flag --- mrgrctrnl | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/mrgrctrnl b/mrgrctrnl index 131894e..4f090d1 100755 --- a/mrgrctrnl +++ b/mrgrctrnl @@ -9,10 +9,11 @@ usage() { cat <<-END mrgrctrnl: make magic ssh tunnels - usage: mrgrctrnl [-h] [-c CONF] + usage: mrgrctrnl [-h] [-c CONF] [-d] -h show this help -c CONF use config file CONF. + -d do a dry run: don't actually tunnel . default: \$XDG_CONFIG_HOME/mrgrctrnl/config END @@ -32,11 +33,13 @@ die() config="${XDG_CONFIG_HOME:=$HOME/.config}/mrgrctrnl/config" pidf=/tmp/mrgrctrnl.pid +dry_run=false; -while getopts hc: opt; do +while getopts hc:d opt; do case "$opt" in h) usage ;; c) config="$OPTARG" ;; + d) dry_run=true ;; \?) usage 2 ;; *) usage 2 ;; esac @@ -44,7 +47,7 @@ done shift "$((OPTIND - 1))" [ -f "$config" ] || die "Need a config! Edit $config" -[ -e "$pidf" ] && { +[ -e "$pidf" ] && ! "$dry_run" && { while read -r pid; do kill "$pid" done < "$pidf" @@ -54,6 +57,13 @@ shift "$((OPTIND - 1))" awk '{sub(/#.*$/,"");print}' "$config" | while read -r machine user local remote do + [ -z "$machine" ] || [ -z "$user" ] || + [ -z "$local" ] || [ -z "$remote" ] && + continue + + echo ssh -N "$user@$machine" -L "$local:$remote" + + $dry_run || while : do ssh -N "$user@$machine" -L "$local:$remote" -- cgit 1.4.1-21-gabe81