How to execute a ".profile" depending on the server from where the user is connected.

Hello,

I have two Solaris servers on a cluster. I have created the same user "X"on the two nodes (same UID and same GID). The file ".profile" of this user "X" is located in a filesystem that is seen by the two nodes.

Each server should have a ".profile" of this user different of the other server.

I want to create a ".profile" that detect from what server the user "X" isconnected and then execute the right ".profile".

Any ideas ?

thanks

What about this. Let's assume the two hostnames are server1 and server2. Then write the .profile as

. ~/.profile.$(hostname)

and the two files .profile.server1 and .profile.server2 are the actual profiles.

---------- Post updated at 11:48 ---------- Previous update was at 11:47 ----------

... and if there are identical parts in both profiles, then just put these parts into .profile itself.

Thanks for your answer. Just one question: when the user connect to the server, it's the file ".profile" that will be executed and not ".profile.server1" or ".profile.server2" ?

The login shell "includes" (not executes) the .profile file of the user. This file may include other files with the '.' (dot) command.

But this will execute the two ".profile" files ?

The shell only knows about .profile, everything else is subject to what you write into this file. For example, including another file.

If the user has access to the same $HOME/.profile when logging in on both systems, you can include something like:

case "$(uname -n)" in
(server1) do stuff you only want when you login on server1 ;;
(server2) do stuff you only want when you login on server2 ;;
esac

in your .profile.