1830498 Members
2294 Online
110006 Solutions
New Discussion

User => IP-Adress

 
SOLVED
Go to solution
Christoph Rothe_3
Frequent Advisor

User => IP-Adress

Hi everyone,

i am looking for a solution for the following:

Actually we have two applications on two servers. On both of the servers there are users which have to log into UNIX to use the application. The usernames on both machines are equal for each user, but the .profile is not as the applications use different versions of JRE etc.

Now we are migrating the applications to a cluster on a new high performance system and want them to be able to run on one cluster node.

The Problem is, that the same user must have different profiles depending on the ip-adress (each of them is assigned to a virtual interface on the machine) on which they log on, as this adress indicates the application the user wants to use.

Has anyone got a solution for the problem of determining on which interface a UNIX-User connected to a machine ?

The idea behind this is, to determine the ip adress / interface on which the user connected and run the correct part of .profile to set environment variables etc.

I tried some tricks with ps -fp $$ to get the tty but I cannot obtain the IP-Adress which the tty is connected to.
I also tried netstat and lsof but they were not showing enough information for the assignment of a user login to the interface he connected on.

Any Ideas ?

Christoph Rothe
5 REPLIES 5
LucianoCarvalho
Respected Contributor

Re: User => IP-Adress

hi,

You can try to use "who -u | grep tty" it will give the address/host name of the machine from where the connection comes.

regards
Rainer von Bongartz
Honored Contributor
Solution

Re: User => IP-Adress

Christoph,

You can do this with lsof

in /etc/profile create a function like this:

function pkg_loc
{
P_ID=$$
TTY=`tty`
TTY=`basename $TTY`

PP_ID=$PPID

IP[1]='A.B.C.D' # pkg1
IP[2]='E.F.G.H' # pkg2

for n in 1 2
do

SV[$n]=`/usr/contrib/bin/lsof -i @${IP[$n]} | grep $PP_ID | grep 0u | grep telnetd | awk ' { print $9 } ' | cut -d : -f 1`

if [ x${SV[$n]} != x ]; then
SV_RETURN=${SV[$n]}
SV_RETURN=`echo $SV_RETURN | cut -d . -f 1`
fi
done
}

Then call pkg_loc

pkg_loc

case $SV_RETURN in
pkg1)
export xxxxx
;;
pkg2)
export yyyyy
;;
*)
echo "Error: No host or package found!" > /dev/null
esac

Regards
Rainer
He's a real UNIX Man, sitting in his UNIX LAN making all his UNIX plans for nobody ...
Ravi_8
Honored Contributor

Re: User => IP-Adress

Hi

try this

#finger
never give up
Christoph Rothe_3
Frequent Advisor

Re: User => IP-Adress

Thanks Rainer,

9 out of 10 points. This is nearly what I need :-)

Unfortunately under some circumstances the $PPID of the shell executing is not the telnetd :-( But with some coding in perl, I will get the result I wanted. MANY thanks!

Christoph
Christoph Rothe_3
Frequent Advisor

Re: User => IP-Adress

It's me again.

I now wrote a perl script doing what I want... nearly.

Have you tried your script when logged in via xterm ? xterm seems to always open a connection from the interface the routing table tells it to use and not via the (virtual) interface I used for the original connect.

Has anyone any idea how to determine the interface a user connected to when using xterm ?

Christoph