reset all tunnels
This commit is contained in:
@@ -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" )
|
||||||
@@ -119,23 +136,27 @@ function read_config() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function run_args() {
|
function run_args() {
|
||||||
if [[ -z "$2" ]]; then
|
if [[ -z "$2" ]]; then
|
||||||
# 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"
|
||||||
else
|
line=$( grep "^$1:" "$CONF" )
|
||||||
echo No such host
|
switches=$( echo "$line" | parse_switches )
|
||||||
cat "$CONF"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
host="$1"
|
echo No such host
|
||||||
shift 1
|
cat "$CONF"
|
||||||
switches=$( echo "$host: $@" | parse_switches )
|
exit 1
|
||||||
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\""
|
else
|
||||||
exit $?
|
host="$1"
|
||||||
|
shift 1
|
||||||
|
line="$host: $@"
|
||||||
|
switches=$( echo "$line" | parse_switches )
|
||||||
|
fi
|
||||||
|
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 $?
|
||||||
}
|
}
|
||||||
|
|
||||||
function run_command() {
|
function run_command() {
|
||||||
@@ -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 ))
|
||||||
|
|||||||
Reference in New Issue
Block a user