From: zxmwl01@hp10.zdv.uni-tuebingen.de (Joern Wilms)
Subject: Re: User Connecting from...?
Date: 1996/10/15 [thread overview]
Message-ID: <53vd6j$lpt@newsserv.zdv.uni-tuebingen.de> (raw)
In-Reply-To: 53tkt6$p2f@alpha.delta.edu
Keith DeLong (keith@alpha.delta.edu) wrote:
: Is there a quick way (inside a shell script) to ask the system which
: IP (or domain name) a user has logged in from? Kind of like "who -M" does
: but only the host name for the user running the script.
Hi,
this is what I do in some shell-scripts that automagically set the DISPLAY
variable to the machine the user logged onto from. Note that when using tcsh
there is a variable REMOTEHOST that solves the task for you automatically
(if you've set up tcsh that way):
### O/S, hostname, etc.
setenv SYSTEM `uname`
setenv HOSTNAME `hostname | awk -F. '{print $1}'`
set TTYENV="`tty |& cat`"
### Most tcsh (but not all!) set REMOTEHOST to the machine we're logging in
### from. If that's the case: use it! If not: do some logic to find the
### name we're logging in from. TTYENV contains either the tty or "not a
### tty"
if ( ${?REMOTEHOST} != 0) then
setenv RHOSTNAME $REMOTEHOST
else
if ( "$TTYENV" == "not a tty" ) then
setenv RHOSTNAME $HOSTNAME
else
setenv TTY `tty | awk -F/ '{print $NF}'`
setenv RHOSTNAME `finger $user|grep from|grep $TTY|head -1|awk '{a=$NF} {FS=":"} {split(a,b)} {FS="."} {split(b[1],f)} {print f[1]}'`
if ($RHOSTNAME == "") setenv RHOSTNAME $HOSTNAME
if ($RHOSTNAME == "from") setenv RHOSTNAME $HOSTNAME
if ($RHOSTNAME == \:0) setenv RHOSTNAME $HOSTNAME
endif
endif
if ($RHOSTNAME == \:0.0) setenv RHOSTNAME $HOSTNAME
The central line in the script is the `finger...` line. Works for me
on Ultrix 4.2, Ultrix 4.4, OSF 3.2C, HP-UX 9.5.0, HP-UX 10.1.0, Solaris
(note that not all commands in the awk script do something on the different
machines; I need all of them only in the case of HP-UX but they don't hurt).
Cheers
: --Keith
: --
: ----------------------------------------------------------------------------
: Keith DeLong (keith@alpha.delta.edu) [http://www.delta.edu/~keith]
: ----------------------------------------------------------------------------
--
Joern Wilms Linsenbergstr. 33
Institute for Astronomy and Astrophysics D-72074 Tuebingen
University of Tuebingen (phone) +49 7071 29-76128
Waldhaeuser Str. 64 (fax) +49 7071 29-3458
D-72076 Tuebingen wilms@astro.uni-tuebingen.de
Germany
prev parent reply other threads:[~1996-10-15 4:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-10-14 4:00 User Connecting from...? Keith DeLong
1996-10-15 4:00 ` Joern Wilms [this message]
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox