Operating System - HP-UX
1827293 Members
2827 Online
109717 Solutions
New Discussion

Pointing .profile to use Environmental Variables from script

 
SOLVED
Go to solution
Doug_85
Regular Advisor

Pointing .profile to use Environmental Variables from script

HP-UX 11.0 L2000

Currently setting up users to use 5 different environmental variable scripts located in /home/profiles. Each user will be pointed to their own corresponding script.

Things Done
1. 5 scripts created in /home/profiles directory
2. entered "exec /home/profiles/budgetprof.sh" at end of .profile in test account
3. permissions were changed on scripts in order for users to run scripts

Questions:

1. What's the proper way of sourcing these 5 scripts from the users .profile?

2. Will any additional modifications be needed to the following files in the users home directory?
.cshrc
.exrc
.login
prefs.ora

3. Any examples or suggestions would be great.

Thanks,
Doug



7 REPLIES 7
RAC_1
Honored Contributor
Solution

Re: Pointing .profile to use Environmental Variables from script

man ksh, sh-posix

ENV=$HOME/env_script

Anil
There is no substitute to HARDWORK
A. Clay Stephenson
Acclaimed Contributor

Re: Pointing .profile to use Environmental Variables from script

The key to doing this is simply something like:

export VAR1=111
export VAR2=222

This is put in a file (not-writable by a regular user) for example, /usr/local/bin/myenv.sh

Now each .profile or batch script should include this file via the dot "." command.

. /usr/local/bin/myenv.sh


myenv.sh must not contain an exit or return because this is not run as a child process but simply becomes part of the shell.
If it ain't broke, I can fix that.
Steve McKenna_3
Advisor

Re: Pointing .profile to use Environmental Variables from script

Doug,

I would shy away from /home/profiles as the directory name for these "source-ins". It may cause confusion at some point down the road. Perhaps /usr/envvars or something like that instead.

All of the other files remain the same, simply add . /usr/envvars/envscript1 to the .profile in /home/julie for user "julie". [Note the 'dot-space' on the line doing the sourcing.] As stated in another post, be careful to avoid having exit in your env scripts. You can set variables, create aliases, change to a different directory, set a special system prompt, etc in this manner.

Cheers,

...Steve...
Steve McKenna_3
Advisor

Re: Pointing .profile to use Environmental Variables from script

oops!

that should have been /usr/local/envvars

mea culpa!
Jim Butler
Valued Contributor

Re: Pointing .profile to use Environmental Variables from script

If you are setting up users, you can create add user templates in sam which your accounts people can use, and in those templates actually call the create scripts from the etc directory to customize each individualized user so that you don't have to add a mess of junk to /etc.

the default files are /etc/d.profile (these are the ones copied to the /users directory)

browse through sam to see what I'm talking about in the help section of adding users.
good luck
Man The Bilge Pumps!
Doug_85
Regular Advisor

Re: Pointing .profile to use Environmental Variables from script

I went ahead and added the /home/profiles directory to the search path as shown below. The budgetprof.sh is one of the shell scripts that is ran from this directory. Everything is working great but I will come up with a better name and location.


Thanks for all your help. Bonus points will be awarded for any additional suggestions.

Thanks,
Doug
Robert Salter
Respected Contributor

Re: Pointing .profile to use Environmental Variables from script

As stated earlier, nobody wants to junk up /etc, but if you plan on adding new users and having them use one of the various environments you've set, you could copy the /etc/skel directory and it's contents (.cshrc, .exrc, .login, and .profile) to other diretories, i.e. /etc/skel1, etc/skel2, ..., and modify the .profiles to add your environment scripts. That way when adding a new user, from command line, i.e.

useradd -g users -d /home/newbie -s /usr/bin/sh -c "New User" -m -k /etc/skel2 newbie
They'll get the environment you want them to have.

bueno bye
Time to smoke and joke