1832379 Members
2888 Online
110041 Solutions
New Discussion

detect ip address

 
kamal_15
Regular Advisor

detect ip address

hi all

i want to know
how can i detect who is login server and what commands he/she written
i do the following in /etc/profile

export HISTFILE=/tmp/sh.history.$LOGNAME

but this procedure can't detect IP address for that user.


help

kamal
6 REPLIES 6
Biswajit Tripathy
Honored Contributor

Re: detect ip address

Parse "who -R am i" output in .profile (by using awk)
to get the IP address/hostname of the system user
is logging in from and add that to the HISTFILE name.

- Biswajit
:-)
steven Burgess_2
Honored Contributor

Re: detect ip address

Hello Kamal

last -R | grep

Will show the ip address they are logged on from

lastb -R

Will show you failed logins

HTH

Steve
take your time and think things through
steven Burgess_2
Honored Contributor

Re: detect ip address

And of course

who -R

for current users

Steve
take your time and think things through
kamal_15
Regular Advisor

Re: detect ip address

Dear Biswajit Tripathy

can u display more

step by step (i didn't use awk before)

thankx
lawrenzo
Trusted Contributor

Re: detect ip address

who -R am i |awk '{print $6}'

This will print the 6th field from the command who -R am i.

HTH
hello
Biswajit Tripathy
Honored Contributor

Re: detect ip address

Try this in .profile :

whoami=`who -R am i | awk '{print $6}'`
client=${whoami##*\(}
client=${client%\)}
export HISTFILE="/tmp/sh_history.$LOGNAME.$client"

This should set HISTFILE to /tmp/sh_history.NAME.host.company.com

Hope this helps.
- Biswajit
:-)