[comp.unix.questions] overkill

merlyn@iwarp.intel.com (Randal Schwartz) (07/24/89)

In article <1989Jul22.222552.11416@ctr.columbia.edu>, seth@ctr (Seth Robertson) writes:
| 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!!!

heh heh

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

Sure you can.  If you get a TERM type, you're rlogin, if not, itza
telnet.  But, the original request was for rlogin, so read on....

| 
| : {$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

Too many processes... try:

case "$TERM" in
sun)
	case `tty` in
	*ttyp*)
		/usr/5bin/echo "\\033]lRLOGIN:`hostname`\\033\\\\";;
	esac;;
esac

NEVER EVER EVER make your .profile slow!  You'll regret it, over and
over again.

Just another UNIX (and now Sun) hacker...
-- 
/== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\
| on contract to Intel, Hillsboro, Oregon, USA                           |
| merlyn@iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn	         |
\== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/

guy@auspex.auspex.com (Guy Harris) (07/26/89)

>Sure you can.  If you get a TERM type, you're rlogin, if not, itza
>telnet.

Sorry, wrong answer; the 4.3BSD version of "telnet" uses (or abuses - it
doesn't follow the protocol, but I'll let those who care one way or the
other argue the point) the "terminal type" option to "telnet" to set
TERM on the remote machine.  Said version is the basis of the one in
4.x; I don't know if it's in 3.x or not.

(Not that it matters, since they probably want the label for either
one....)

>case "$TERM" in
>sun)
>	case `tty` in
>	*ttyp*)
>		/usr/5bin/echo "\\033]lRLOGIN:`hostname`\\033\\\\";;
>	esac;;
>esac

Well, two problems with that:

	1) pseudo-ttys *do* have names that don't contain "ttyp", like
	   "ttyq0", "ttyq1", "ttyq1", etc.

	2) TERM is "sun-cmd", not "sun", in a "cmdtool" window.

Both fixable, of course, with different patterns in the "case"
construct.