shell menu utils
This commit is contained in:
@@ -7,7 +7,7 @@ MAGIC_TIME=525601
|
||||
|
||||
BASE="base64 -w 0"
|
||||
UNBASE="base64 -d"
|
||||
if [[ "$OSTYPE" = "darwin"* ]]; then
|
||||
if [[ "$OSTYPE" = "darwin"* ]]; then
|
||||
BASE="base64"
|
||||
UNBASE="base64 -D"
|
||||
fi
|
||||
@@ -22,13 +22,13 @@ Configuration stored in: $CONF
|
||||
|
||||
If run with arguments, runs an ssh tunnel with arguments:
|
||||
ssh-tunnelier hostname [local-port] remote-port
|
||||
|
||||
|
||||
If local port missing, the same port assumed in local
|
||||
"
|
||||
exit 0
|
||||
}
|
||||
|
||||
for (( i=1; i<=$#; i++ )); do
|
||||
for (( i=1; i<=$#; i++ )); do
|
||||
[[ ${!i} = "-h" ]] && _helpexit
|
||||
[[ ${!i} = "--help" ]] && _helpexit
|
||||
done
|
||||
@@ -50,7 +50,7 @@ colRow=$( _qCol z S )
|
||||
colMenu=$( _qCol z y )
|
||||
colWarn=$( _qCol z R )
|
||||
|
||||
function fpgrep() {
|
||||
function fpgrep() {
|
||||
[[ -z $( pgrep -x -u $UID "$@" ) ]] && { echo '----'; return; }
|
||||
pgrep -x -u $UID "$@" | xargs ps -o pid,start,args
|
||||
}
|
||||
@@ -75,10 +75,10 @@ function list_all_ssh() {
|
||||
printf "${colTitle}Enter PID to kill, empty to return $colZ\n"
|
||||
printf "${colTitle}Outgoing SSH processes\n"
|
||||
printf "${colTitle}=============================================\n${colRow}"
|
||||
fpgrep ssh
|
||||
fpgrep ssh
|
||||
printf "${colTitle}Incoming SSH processes\n"
|
||||
printf "${colTitle}=============================================\n${colRow}"
|
||||
fpgrep sshd
|
||||
fpgrep sshd
|
||||
read -t 600 inputpid
|
||||
|
||||
[[ "$inputpid" =~ $number_re ]] && {
|
||||
@@ -111,16 +111,16 @@ function run_command() {
|
||||
}
|
||||
|
||||
function ask_to_kill() {
|
||||
printf "${colRow}"
|
||||
ps -o pid,bsdstart,args "$1"
|
||||
printf "\n k kill\n t terminate${colZ}\n"
|
||||
printf "${colRow}"
|
||||
ps -o pid,bsdstart,args "$1"
|
||||
printf "\n k kill\n t terminate${colZ}\n"
|
||||
read -t 600 input2
|
||||
[[ "$input2" = "k" ]] && kill $1
|
||||
[[ "$input2" = "t" ]] && kill -9 $1
|
||||
}
|
||||
|
||||
|
||||
[[ -n "$2" ]] && {
|
||||
[[ -n "$2" ]] && {
|
||||
run_args "$@"
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ while true; do
|
||||
ids=()
|
||||
i=1
|
||||
printf "\n${colTitle}=============================================\n"
|
||||
printf "${colTitle} List of tunnels:${colZ}\n"
|
||||
printf "${colTitle} List of tunnels:${colZ}\n"
|
||||
printf "${colTitle} (q)uit (e)dit (l)ist ssh [%s]${colZ}\n" $( date +%H:%M )
|
||||
printf "${colTitle}=============================================\n"
|
||||
printf "${colRow}ID PID command\n"
|
||||
@@ -142,12 +142,12 @@ while true; do
|
||||
[[ "$input" = "0" ]] && continue
|
||||
[[ "$input" =~ $number_re ]] && {
|
||||
j=$(( $input - 1 ))
|
||||
[[ $j -gt $(( $i - 1 )) ]] && {
|
||||
[[ $j -gt $(( $i - 1 )) ]] && {
|
||||
printf "${colWarn}No such tunnel number${colZ}\n"
|
||||
continue
|
||||
}
|
||||
|
||||
printf "\n${colTitle}Tunnel command: %s${colZ}\n" "$( echo "${ids[$j]}" | $UNBASE )"
|
||||
|
||||
printf "\n${colTitle}Tunnel command: %s${colZ}\n" "$( echo "${ids[$j]}" | $UNBASE )"
|
||||
this_pid="$( get_pid "${ids[$j]}" )"
|
||||
[[ -n "$this_pid" ]] && {
|
||||
# PID exists, ask to kill
|
||||
|
||||
Reference in New Issue
Block a user