[comp.unix.questions] utility to determine rlogin?

gerald@ge1cbx.UUCP (Gerald Aden) (04/26/88)

Is there a utility that returns an indication as to whether or not
I am remotely logged in.  I want to put it in my .login file where
I want to perform certain functions if I am remotely logged in.  My
home directory is NFS mounted on all the machines on our network.

Thanks in advance,
Gerald Aden
-- 
Quotron Systems Inc.	| Phone: (213)827-4600 x4254
5454 Beethoven Street	| uucp: {cbosgd,ihnp4,trwrb}!scgvaxd!janus!ge1cbx!gerald
Post Office Box 66914	|        uunet!janus!ge1cbx!gerald
Los Angeles, CA 90066	|

jerryp@cmx.npac.syr.edu (Jerry Peek) (06/05/88)

In article <204@ge1cbx.UUCP> gerald@ge1cbx.UUCP (Gerald Aden) writes:
> Is there a utility that returns an indication as to whether or not
> I am remotely logged in.  I want to put it in my .login file where
> I want to perform certain functions if I am remotely logged in.  My
> home directory is NFS mounted on all the machines on our network.

You didn't say what OS you're using.  And I don't know how it's configured.
But I can tell you how I did the same kind of thing on a 4.3BSD system.  It
turned out to be really useful.  Most of our terminals were connected to:
	- a dataswitch (like Sytek, Develcon, etc.) or
	- a network (for rlogin, telnet, etc.)
So, we couldn't make the same kinds of assumptions (like "ttyG3 is always a
vt100") that sites with hardwired terminals did.

First, we labeled all the entries in the /etc/ttys file to tell what sort of
device was hooked to each one.  (Our /etc/ttys used to label all terminals as
"plugboard".  We changed them to read "dw3", "develcon", "sytek", "network",
etc.)  So, all the rlogin-able ports were labelled "network" in /etc/ttys.

Then, I wrote a shell script named "ttykind".  It took a tty name on the
commandline (default: current terminal) and output the tty kind from the
/etc/ttys file.  For example, let's say I'm remotely logged in on /dev/ttyp3,
and /etc/ttys shows it as a "network" tty.  Running "ttykind" will give:
	% ttykind
	network

So, setting up my .login was easy.  I put a test like this one in it:

	switch ("`ttykind`")
	case network:
		# do stuff for network login
	case xxx:
		# do stuff for xxx login
	default:

DISCLAIMERS: The /etc/ttys file is important; you shouldn't edit it without
thinking about what else will be affected.  Also, on some non-4.3BSD systems,
there are two files named (I think) /etc/ttys and /etc/ttytype; they work in a
different way than the 4.3BSD /etc/ttys file.  Finally, it's been quite a
while since I used that system; I hope I haven't forgotten any details.

--Jerry Peek, Northeast Parallel Architectures Center, Syracuse, NY 13244-1260
  jerryp@cmx.npac.syr.edu
  +1 315 423-4120

rbj@icst-cmr.arpa (Root Boy Jim) (06/09/88)

   From: Jerry Peek <jerryp@cmx.npac.syr.edu>

   Then, I wrote a shell script named "ttykind".  It took a tty name on the
   commandline (default: current terminal) and output the tty kind from the
   /etc/ttys file.  For example, let's say I'm remotely logged in on /dev/ttyp3,
   and /etc/ttys shows it as a "network" tty.  Running "ttykind" will give:
	   % ttykind
	   network

   So, setting up my .login was easy.  I put a test like this one in it:

	   switch ("`ttykind`")
	   case network:
		   # do stuff for network login
	   case xxx:
		   # do stuff for xxx login
	   default:

Why not just do `switch ($term)'? You don't need ttykind, except for
finding out *other* peoples terminal types.

   --Jerry Peek, Northeast Parallel Architectures Center, Syracuse, NY 13244
     jerryp@cmx.npac.syr.edu
     +1 315 423-4120

	(Root Boy) Jim Cottrell	<rbj@icst-cmr.arpa>
	National Bureau of Standards
	Flamer's Hotline: (301) 975-5688
	The opinions expressed are solely my own
	and do not reflect NBS policy or agreement
	My name is in /usr/dict/words. Is yours?

richl@penguin.USS.TEK.COM (Rick Lindsley) (06/16/88)

Jerry Peek <jerryp@cmx.npac.syr.edu> writes:

   So, setting up my .login was easy.  I put a test like this one in it:

       switch ("`ttykind`")
       case network:
	       # do stuff for network login
       case xxx:
	       # do stuff for xxx login
       default:
    
In article <16109@brl-adm.ARPA> rbj@icst-cmr.arpa (Root Boy Jim) writes:
    
    Why not just do `switch ($term)'? You don't need ttykind, except for
    finding out *other* peoples terminal types.

Because rlogin will pass the terminal type across for you. $term may not
provide the information you want.

Rick

maujd@warwick.UUCP (Geoff Rimmer) (06/21/88)

In article <518@cmx.npac.syr.edu> jerryp@cmx.npac.syr.edu (Jerry Peek) writes:
>In article <204@ge1cbx.UUCP> gerald@ge1cbx.UUCP (Gerald Aden) writes:
>> Is there a utility that returns an indication as to whether or not
>> I am remotely logged in.  I want to put it in my .login file where
>> I want to perform certain functions if I am remotely logged in.  My
>> home directory is NFS mounted on all the machines on our network.
>
>	[ a lot of techno stuff ]

What's wrong with a simple shell script like this?

----------------------------------------------------------------------
#!/bin/csh -f

#  /*****************************************************************\
# |*  PROGRAM : isrlogin -- tests to see if the machine is a remote
# |*			     login or not.
# |*	(c) Geoff Rimmer 1988
# |*
# |*  $Revision: 1.2 $   
# |*  $Date: 88/02/18 17:58:43 $
# |*  $Author: maujd $   
# |*
# |*  $Header: isconsole,v 1.2 88/02/18 17:58:43 maujd Locked $
#  \*****************************************************************/

if ( "`who am i | egrep -c '\('`" != 0 ) then
  exit 0
endif
exit 1
----------------------------------------------------------------------
It works because 'who am i' (note spaces) will print 

	garnet!maujd    ttyp0   Jun 21 11:53

for a non-remote login, and

	opal!maujd    ttyp7   Jun 21 13:20      (garnet)

for a remote login (with the original machine shown in brackets).
Testing for the brackets with egrep, shows whether it is a remote
login or not.

Use the script as follows :-

(from csh ...)

	if { isrlogin } then
		# is remotely logged in	...
		......
	else
		# isn't remotely logged in ...
		......
	endif


(from sh ...)

	if isrlogin ; then
		# is remotely logged in ...
		......
	else
		# isn't remotely logged in ...
		......
	fi

(from ksh ...)

	who knows??? :-)

>--Jerry Peek, Northeast Parallel Architectures Center, Syracuse, NY 13244-1260
>  jerryp@cmx.npac.syr.edu
>  +1 315 423-4120

Geoff.
	------------------------------------------------------------
	Geoff Rimmer, Computer Science, Warwick University, UK.
			maujd@uk.ac.warwick.opal

	"Maybe one day I'll actually manage to keep the lentils off
	 the floor!" - The Young Ones. (BBC TV)
	------------------------------------------------------------

rbj@cmr.icst.nbs.gov (Root Boy Jim) (06/24/88)

? From: Rick Lindsley <richl@penguin.uss.tek.com>

? Jerry Peek <jerryp@cmx.npac.syr.edu> writes:

?    So, setting up my .login was easy.  I put a test like this one in it:

?        switch ("`ttykind`")
?        case network:
? 	       # do stuff for network login
?        case xxx:
? 	       # do stuff for xxx login
?        default:
?     
? In article <16109@brl-adm.ARPA> rbj@icst-cmr.arpa (Root Boy Jim) writes:
?     
?     Why not just do `switch ($term)'? You don't need ttykind, except for
?     finding out *other* peoples terminal types.

? Because rlogin will pass the terminal type across for you. $term may not
? provide the information you want.

? Rick

Well, I see your point, but still disagree. If I rlogin from a sun console
to a VAX, why would I want anything other than a Sun termcap?

	(Root Boy) Jim Cottrell	<rbj@icst-cmr.arpa>
	National Bureau of Standards
	Flamer's Hotline: (301) 975-5688
	The opinions expressed are solely my own
	and do not reflect NBS policy or agreement
	Careful with that VAX Eugene!

jerryp@cmx.npac.syr.edu (Jerry Peek) (06/26/88)

A while back, I wrote about a utility called "ttykind" that looks up your
terminal type in /etc/ttys.

In article <16281@brl-adm.ARPA> rbj@cmr.icst.nbs.gov (Root Boy Jim) writes:
> ? From: Rick Lindsley <richl@penguin.uss.tek.com>
> 
> ? In article <16109@brl-adm.ARPA> rbj@icst-cmr.arpa (Root Boy Jim) writes:
> ?     Why not just do `switch ($term)'? You don't need ttykind, except for
> ?     finding out *other* peoples terminal types.
> 
> ? Because rlogin will pass the terminal type across for you. $term may not
> ? provide the information you want.
> 
> Well, I see your point, but still disagree. If I rlogin from a sun console
> to a VAX, why would I want anything other than a Sun termcap?

It's not just to get the termcap.  Someone posted a note about terminal
concentrators; that's what Rick was talking about, too, I think.  They can
hide the real terminal characteristics.

For instance, I used to use 1200-baud dialup lines a lot (yecch!).  Some
programs check the data rate and adjust to slow lines.  For instance, "vi"
sets a smaller window size at slow speeds.  But our Sytek hid the dialup
lines' speeds; all Sytek port connections to our VAX were at 9600 baud.
We had the same problem on network connections; the real terminal speed was
lost.  So, I put a test in .login for the output of "ttykind" -- if the port
was sytek or network, I'd be prompted for the *real* data rate, which was
stored in an envariable named REAL_BAUD -- that was used to set aliases,
EXINIT and RNINIT envariables, etc., that made baudrate-sensitive programs
work right on sytek and network connections.

--Jerry Peek, Northeast Parallel Architectures Center, Syracuse, NY
  jerryp@cmx.npac.syr.edu
  +1 315 423-4120

rbj@cmr.icst.nbs.gov (Root Boy Jim) (07/02/88)

? From: Geoff Rimmer <maujd@warwick.uucp>

? What's wrong with a simple shell script like this?

? #!/bin/csh -f

You don't need to use any csh features. While I am not opposed to
csh scripts in general (in fact any nontrivial script that I do not
care about portability *is* written in csh), you should use sh here.

[script deleted]

? 	opal!maujd    ttyp7   Jun 21 13:20      (garnet)

? for a remote login (with the original machine shown in brackets).

Brackets? Brace {yourself} for this [parenthetical] expression :-)

	(Root Boy) Jim Cottrell	<rbj@icst-cmr.arpa>
	National Bureau of Standards
	Flamer's Hotline: (301) 975-5688
	The opinions expressed are solely my own
	and do not reflect NBS policy or agreement
	Careful with that VAX Eugene!

dik@cwi.nl (Dik T. Winter) (07/03/88)

From: Geoff Rimmer <maujd@warwick.uucp>
 > 	opal!maujd    ttyp7   Jun 21 13:20      (garnet)
 > 
 > for a remote login (with the original machine shown in brackets).
 > 
Yes:
	boring!dik    ttyp2   Jun 30 16.15      (tc-2)
(this one is faked, but it is similar)
this is not a remote login, but a login through a terminal concentrator.
The "original machine" tells its tale.
-- 
dik t. winter, cwi, amsterdam, nederland
INTERNET   : dik@cwi.nl
BITNET/EARN: dik@mcvax