[comp.unix.questions] How can a login script determine if the session is remotely logged in?

rtm@tellab5.tellabs.CHI.IL.US (Roberto Michelassi) (07/21/89)

I am currently a ksh user running on a Sun 3/60 with SunOS 4.0 and would like
to add a feature to my .profile or .kshrc file that would update the tool 
header of the window to display the message "RLOGIN" when I remotely log into
another machine. I know how to send the appropriate escape sequences to the
window to update the tool header, what I don't know is how to determine when
a script is being executed in a remotely logged in session.

I would greatly appreciate any suggestions you might have.

seth@ctr.columbia.edu (Seth Robertson) (07/23/89)

In article <1448@tellab5.tellabs.CHI.IL.US> rtm@tellab5.UUCP (Roberto Michelassi) writes:
>
>I am currently a ksh user running on a Sun 3/60 with SunOS 4.0 and would like
>to add a feature to my .profile or .kshrc file that would update the tool 
>header of the window to display the message "RLOGIN" when I remotely log into
>another machine.

Nothing easier!!!

(Of course I can't tell whether it is telnet or rlogin...)

: {$tty:=`tty`}
: {$pty:=`basename $tty`}

##
# Is this a pty (e.g. not console, dialup, or serial port

if echo $pty | grep ttyp > /dev/null 2>&1  ## Note Yuck!  Echo|grep??
## Also, if you have lots of ptys, you will need to search for
## more pseudo terminals than ttyp (e.g. ttyr ttys, etc.)

 then
# Is this a login shell? (e.g. not su, not suntools, not emacs)
  if basename $0 | grep -e "-ksh" > /dev/null 2>&1  ## Less yucky than before
   then
    echo This is a a remote session.
    echo That is because is on a pseudo-terminal and was started
    echo by login.  \(But not necessarily a rlogin\)
   fi
 fi


I even tested it!!! (Wow, can get better service that that!!! :-) :-)

-- 
					-Seth Robertson
					 seth@ctr.columbia.edu