ssh-fwd : prendre en compte les redirections en dehors d'un control
master
This commit is contained in:
parent
1f68407d9b
commit
6a905e39cf
1 changed files with 18 additions and 8 deletions
26
bin/ssh-fwd
26
bin/ssh-fwd
|
@ -1,5 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
step() {
|
||||
printf '\033[1;32m*\033[0m \033[1m%s...\033[0m\n' "$*"
|
||||
}
|
||||
|
||||
error() {
|
||||
>&2 printf '\033[1;31mERROR:\033[0m \033[1m%s\033[0m\n' "$error"
|
||||
return "$1"
|
||||
|
@ -18,22 +22,28 @@ start_forwarding() {
|
|||
-L "${local_port}:${target}:${distant_port}" \
|
||||
"$@" \
|
||||
"$ssh_host"
|
||||
}
|
||||
}
|
||||
|
||||
show_redirection_info() {
|
||||
lsof -i -P -n | awk '($1 == "ssh" && $10 == "(LISTEN)" && $9 ~ /.*:'"${local_port}"'/) { print }'
|
||||
}
|
||||
|
||||
get_ssh_pid() {
|
||||
show_redirection_info | awk '{ print $2 }' | sort | uniq
|
||||
}
|
||||
|
||||
# Supprimer la redirection SSH
|
||||
stop_forwarding() {
|
||||
start_forwarding -O cancel
|
||||
if [ "$?" -eq 255 ]; then
|
||||
echo "Okay then, brutally killing SSH..."
|
||||
kill "$(get_ssh_pid)"
|
||||
fi
|
||||
}
|
||||
|
||||
# Retourner 0 si le port de la redirection est déjà utilisé par SSH
|
||||
is_forwarding_active() {
|
||||
lsof -i -P -n \
|
||||
| awk '($1 == "ssh" && $10 == "(LISTEN)") { print $9 }' \
|
||||
| sed 's/.*://' | sort | uniq | grep -q "$local_port"
|
||||
}
|
||||
|
||||
step() {
|
||||
printf '\033[1;32m*\033[0m \033[1m%s...\033[0m\n' "$*"
|
||||
[ -n "$(show_redirection_info)" ]
|
||||
}
|
||||
|
||||
# Parser les variables
|
||||
|
|
Loading…
Reference in a new issue