I want to detect from a shell script (more specifically .zshrc) if it is controlled through SSH. I tried the HOST variable but it's always the name of the computer which is running the shell. Can I access the hostname where the SSH session is coming from? Comparing the two would solve my problem.Every time I log in there is a message stating the last login time and host:Last login: Fri Mar 18 23:07:28 CET 2011 from max on pts/1Last login: Fri Mar 18 23:11:56 2011 from maxThis means the server has this information.
How can I detect if the shell is controlled from SSH?
ssh;shell script;zsh
Here are the criteria I use in my ~/.profile:If one of the variables SSH_CLIENT or SSH_TTY is defined, it's an ssh session.If the login shell's parent process name is sshd, it's an ssh session.if [ -n $SSH_CLIENT ] || [ -n $SSH_TTY ]; then  SESSION_TYPE=remote/ssh# many other tests omittedelse  case $(ps -o comm= -p $PPID) in    sshd|*/sshd) SESSION_TYPE=remote/ssh;;  esacfi(Why would you want to test this in your shell configuration rather than your session startup?)