* User Connecting from...?
@ 1996-10-14 4:00 Keith DeLong
1996-10-15 4:00 ` Joern Wilms
0 siblings, 1 reply; 2+ messages in thread
From: Keith DeLong @ 1996-10-14 4:00 UTC (permalink / raw)
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.
--Keith
--
----------------------------------------------------------------------------
Keith DeLong (keith@alpha.delta.edu) [http://www.delta.edu/~keith]
----------------------------------------------------------------------------
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: User Connecting from...?
1996-10-14 4:00 User Connecting from...? Keith DeLong
@ 1996-10-15 4:00 ` Joern Wilms
0 siblings, 0 replies; 2+ messages in thread
From: Joern Wilms @ 1996-10-15 4:00 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1996-10-15 4:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-10-14 4:00 User Connecting from...? Keith DeLong
1996-10-15 4:00 ` Joern Wilms
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox