find station from where is logged in

for secure access purposes I want to know where somebody logs in
working in K shell

I have
who am i= giving user and terminal =gxb pts/4 Jan 22 15:0

finger user => gives all sessions of user

Login name: gxb
Directory: /home/gxb Shell: /sbin/ksh
On since Jan 22 15:05:31 on pts/4 from BS-013
No unread mail
No Plan.

I want to get the BS-013 !!

grep to find the terminal and the corresponding station ( station or ip address )

I tried
grep 'who am i |cut -c12-20' but this is not working

any ideas

Hi ,try:

grep "$(who am i |cut -c12-20)"

Cheers

who -R

could be useful. I am on HP-UX.

who -u

works on every platefrorm ...

Hello,

thank you already
who -R is not working, I am on SINIX ( older Siemens UNIX version)
who -u shows me all the users and the terminal.
I need the station ( is available in finger )

Try this:

finger -m username | awk 'NR==3{print $NF}'

I do not know the awk but it works.
However, this works when the user has 1 session.
He can have more sessions: the virtual terminal is then different and it is important to have the correct terminal-workstation info

as far as logic i had thefollowing in mind
with who am i: i find the virtual terminal
with finger user: i find the several sessions and corresponding terminals and workstations
with ? grep or other I take the correct line based on the terminal from who am i
with cut I take the workstation info out of that line

Try this:

$finger -m username | grep "On since" | awk '{print $NF}'

It would work if in place of the "On Since" I could put the terminal as a result from who am i = who am i |cut -c12-20

It would be better idea to put here exactly what you are looking for rather telling us how you want to acheive it, because you mentioned earlier that you are looking for to get the station name from where user is initiating the connection and I think the command which I have given you suffice your requiremnt, can you please post here your exact requirements.

Thanks.

I try to be more clear:
below is the output of finger gxb

$ finger gxb
Login name: gxb
Directory: /home/gxb Shell: /sbin/ksh
On since Jan 22 15:05:31 on pts/4 from BS-013
1 hour 13 minutes Idle Time
No unread mail
No Plan.

Login name: gxb
Directory: /home/gxb Shell: /sbin/ksh
On since Jan 23 10:58:52 on pts/10 from BS-013
11 minutes Idle Time

Login name: gxb
Directory: /home/gxb Shell: /sbin/ksh
On since Jan 23 11:03:02 on pts/11 from BS-013
23 minutes Idle Time

Login name: gxb
Directory: /home/gxb Shell: /sbin/ksh
On since Jan 23 11:26:14 on pts/12 from BS-014
18 seconds Idle Time

as you can see I connect several sessions ( pts/4 pts/10 pts/11 pts/12) from several locations BS-013 BS-014

I only want to know on what location I logged on

Ok, try:

finger gxb|awk ' /from/ {print $NF}'|sort -u

bye

finger gxb | \
awk '$1=="On" && $(NF-1)=="from" { print $NF }' |\
sort | uniq -c

Jean-Pierre.

Hello

thanks, this gives me the 2 locations.

However I only want the one I am actually working on

Try something like that :

finger gxb | \
awk 'BEGIN {
        "who am i" | getline ;
        tty = $2;
     }
     $1=="On" && $(NF-2)==tty && $(NF-1)=="from" {
        print $NF
     }' 

Jean-Pierre.

Hello

this works OK
thank you all very much for the help

PS: is it possible to assign the output to a variable ?

location=$(
               finger gxb | \
               awk 'BEGIN {
                         "who am i" | getline ;
                         tty = $2;
                      }
                      $1=="On" && $(NF-2)==tty && $(NF-1)=="from" {
                         print $NF
                      }'
              )

Jean-Pierre.

Thank you
works perfectly

best regards

Ghislain