Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!oberon!bbn!uwmcsd1!marque!uunet!mcvax!ukc!warwick!maujd From: maujd@warwick.UUCP (Geoff Rimmer) Newsgroups: comp.unix.questions Subject: Re: utility to determine rlogin? Summary: csh hacks do it in 4 lines! Message-ID: <711@ubu.warwick.UUCP> Date: 21 Jun 88 13:23:43 GMT References: <204@ge1cbx.UUCP> <518@cmx.npac.syr.edu> Sender: news@warwick.UUCP Reply-To: maujd@warwick.UUCP (Geoff Rimmer) Organization: Computer Science, Warwick University, UK Lines: 82 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) ------------------------------------------------------------