utility to determine rlogin?

Geoff Rimmer maujd at warwick.UUCP
Tue Jun 21 23:23:43 AEST 1988


In article <518 at cmx.npac.syr.edu> jerryp at cmx.npac.syr.edu (Jerry Peek) writes:
>In article <204 at ge1cbx.UUCP> gerald at 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 at cmx.npac.syr.edu
>  +1 315 423-4120

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

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



More information about the Comp.unix.questions mailing list