Finding out if you are in an ssh session

Hey,

I'm trying to build customized behavior in a bash script for when it is run within an ssh session. This is how I'm finding out if the current session is ssh:

USER=`whoami`                                                                                                                  
CURRENT_TTY=`ps -Alf | grep $$ | head -n 1 | gawk '{print $13}'`                                                               
(! ( ps -Alf | grep "sshd: $USER@$CURRENT_TTY" | grep -v grep )) > /dev/null                                                   
IS_SSH_SESSION=$?                                                                                                              

I'm wondering if anyone knows of a better way to do this?

/proc/$pid/maps

If you can find sshd, u can find out that your console is a ssh.

no no, I should work more to find it out . sorry.

Depending on your environment, checking SSH_CLIENT and/or SSH_CONNECTION for any contents might do the trick (?).

[house@freyja] env | grep 'SSH_C' # no session, no feedback
[house@mahab] env | grep 'SSH_C' # from within a session
SSH_CLIENT=62.202.13.15 54550 22
SSH_CONNECTION=62.202.13.15 54550 192.168.110.111 22