Come determinare attuale tipo di connessione remota? (Rsh o ssh)
Domanda
vorrei sapere se c'è alcuni metodi per scoprire il tipo di connessione corrente al server remoto (rsh o ssh?). L'ambiente è Solaris 9, Linux SuSE, csh.
Soluzione
È possibile utilizzare echo $SSH_CONNECTION;
. SSH imposterà questa variabile di ambiente sul server remoto. Esso contiene l'IP del client, porta del client, server IP, e la porta del server. Deve essere impostato solo per le connessioni SSH.
Altri suggerimenti
Risposta breve:. Test "$SSH_CLIENT$SSH2_CLIENT$SSH_TTY"
e che è collegato e che è il tuo genitore
Il progetto ha liquidprompt un (bash / zsh) Funzione per farlo, che si presenta come:
# If this is an SSH connection.
if [[ -n "$SSH_CLIENT$SSH2_CLIENT$SSH_TTY" ]] ; then
# This is SSH.
else
# Get the host part of the who am i command.
local sess_src="$(who am i | sed -n 's/.*(\(.*\))/\1/p')"
# Get the name of the parent process.
local sess_parent="$(ps -o comm= -p $PPID 2> /dev/null)"
if [[ -z "$sess_src" && "$sess_src" = *"shepherd" ]] ; then
# This is a qrsh connection (cf. Grid Engine).
elif [[ -z "$sess_src" || "$sess_src" = ":"* ]] ; then
# This is a local connection.
elif [[ "$sess_parent" = "su" || "$sess_parent" = "sudo" ]] ; then
# This is a su/sudo
else
# This (may be) telnet.
fi
fi
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow