1827295 Members
4095 Online
109717 Solutions
New Discussion

Re: login script help

 
SOLVED
Go to solution
Gord Moore
Frequent Advisor

login script help

I've tried to get this working but failed, so I am asking the gurus here to tell me what I'm doing wrong.

The dba's on my systems want to run a different .profile for each system they log on to. We use NIS+ so I can only define one home directory (/home/dba). I renamed the .profile in /u01/dba on node 1 to node1.profile, and the .profile in /u02/dba on node 2 to node2.profile. Then in the .profile in /home/dba I have a case statement.

HOST=`hostname`
case $HOST in
node1)
sh /u01/dba/node1.profile
cd /u01/dba
;;
node2)
sh /u02/dba/node2.profile
cd /u02/dba
;;
esac

The profile scripts have a lot of export commands to set up their environment, but when I run it, none of the exported variables are set.

Why not? What am I doing wrong?
3 REPLIES 3
Solution

Re: login script help

Your spawning a child shell, where the all the env scripts are getting run, but it then exits back to your parent shell, and you lose them all... This should work:

HOST=`hostname`
case $HOST in
node1)
. /u01/dba/node1.profile
cd /u01/dba
;;
node2)
. /u02/dba/node2.profile
cd /u02/dba
;;
esac

The '.' tells the shell to run the commands in the file in the current shell rather than spawning a child process.

HTH

Duncan


I am an HPE Employee
Accept or Kudo
Ian Dennison_1
Honored Contributor

Re: login script help

Methinks this is what is happening,...

When you run a 'sh', it spawns a shell which loads up the profile, then closed the shell and carries on.

Try replacing 'sh' with '.' in the conditionals and see what happens.

eg .
HOST=`hostname`
case $HOST in
node1)
. /u01/dba/node1.profile
cd /u01/dba
;;
node2)
. /u02/dba/node2.profile
cd /u02/dba
;;
esac

Share and Enjoy! Ian
Building a dumber user
A. Clay Stephenson
Acclaimed Contributor

Re: login script help

You already gotten the correct answer BUT here's another part of the equation. These other scripts which are sourced using . MUST NOT have an exit or a return statement or you will exit the foreground process (the shell) and be logged out.
If it ain't broke, I can fix that.