reset all tunnels

This commit is contained in:
Ville Rantanen
2023-02-08 09:11:15 +02:00
parent b69583d371
commit e0eae1d1ea

View File

@@ -57,7 +57,7 @@ function fpgrep() {
} }
function get_id() { function get_id() {
id=$( printf "%s" "$line" | $BASE ) id=$( printf "%s" "$1" | $BASE )
echo -n $id echo -n $id
} }
@@ -108,6 +108,23 @@ function list_all_ssh() {
} }
} }
function reset_all_ssh() {
match="ssh.*sleep.*echo tunnelier"
printf "\n${colTitle}=============================================\n"
printf "${colTitle} List of tunneliers:${colZ}\n"
printf "${colTitle}=============================================\n${colRow}"
if [[ -z $( pgrep -u $UID -f "$match" ) ]]; then
echo 'No tunneliers running.'
return
else
pgrep -u $UID -f "$match" | xargs ps -o pid,start,args
fi
printf "\n k kill all\n t terminate all\n empty returns${colZ}\n"
read -t 600 input1
[[ "$input1" = "k" ]] && pkill -u $UID -f "$match"
[[ "$input1" = "t" ]] && kill -u $UID -9 -f "$match"
}
function read_config() { function read_config() {
while read line; do while read line; do
id=$( get_id "$line" ) id=$( get_id "$line" )
@@ -123,7 +140,9 @@ function run_args() {
# only hostname # only hostname
if grep -q "^$1:" "$CONF"; then if grep -q "^$1:" "$CONF"; then
grep "^$1:" "$CONF" grep "^$1:" "$CONF"
switches=$( grep "^$1:" "$CONF" | parse_switches ) host="$1"
line=$( grep "^$1:" "$CONF" )
switches=$( echo "$line" | parse_switches )
else else
echo No such host echo No such host
cat "$CONF" cat "$CONF"
@@ -132,9 +151,11 @@ function run_args() {
else else
host="$1" host="$1"
shift 1 shift 1
switches=$( echo "$host: $@" | parse_switches ) line="$host: $@"
switches=$( echo "$line" | parse_switches )
fi fi
eval "ssh -f -n $switches \"nice /bin/bash -c 'for ((i=1;i<$MAGIC_TIME;i++)); do cut -f4 -d \\\" \\\" /proc/\\\$PPID/stat | xargs kill -0 || exit ; sleep 60;done'; echo tunnelier $1\"" id=$( get_id "$line" )
eval "ssh -f -n $switches \"nice /bin/bash -c 'for ((i=1;i<$MAGIC_TIME;i++)); do cut -f4 -d \\\" \\\" /proc/\\\$PPID/stat | xargs kill -0 || exit ; sleep 60;done'; echo tunnelier $id\""
exit $? exit $?
} }
@@ -177,7 +198,7 @@ while true; do
i=1 i=1
printf "\n${colTitle}=============================================\n" printf "\n${colTitle}=============================================\n"
printf "${colTitle} List of tunnels: (${LOCALHOSTSYMBOL}=localhost) [%s]${colZ}\n" $( date +%H:%M ) printf "${colTitle} List of tunnels: (${LOCALHOSTSYMBOL}=localhost) [%s]${colZ}\n" $( date +%H:%M )
printf "${colTitle} (q)uit (e)dit (l)ist ssh (i)nstant tunnel${colZ}\n" printf "${colTitle} (q)uit (e)dit (l)ist (i)nstant (r)eset${colZ}\n"
printf "${colTitle}=============================================\n" printf "${colTitle}=============================================\n"
printf "${colRow}ID PID host: ports\n" printf "${colRow}ID PID host: ports\n"
read_config read_config
@@ -188,6 +209,7 @@ while true; do
[[ "$input" = "i" ]] && instant_entry [[ "$input" = "i" ]] && instant_entry
[[ "$input" = "e" ]] && vim "$CONF" [[ "$input" = "e" ]] && vim "$CONF"
[[ "$input" = "l" ]] && list_all_ssh [[ "$input" = "l" ]] && list_all_ssh
[[ "$input" = "r" ]] && reset_all_ssh
[[ "$input" = "0" ]] && continue [[ "$input" = "0" ]] && continue
[[ "$input" =~ $number_re ]] && { [[ "$input" =~ $number_re ]] && {
j=$(( $input - 1 )) j=$(( $input - 1 ))