views:

38

answers:

3

My problem is like this (OS is Sun Solaris):

1) At the boot time I want to start a process using a specific script. I am doing this by putting this script in /etc/init.d (and following other K and S rules)

2) The program which will be called by the script is located at $HOME/xxx/yyy location.

4) I am using 'su - {myuser} -c "{full path of the program}"' in order to execute the script as {myuser}

3) I dont want to hardcode the value of $HOME in the script but want to use the $HOME env variable only. How can I get this $HOME env variable in the shell script? Also what other variables will be available to me?

A: 

Just put

env > env.txt

in the script. After running your script the env.txt file contains all environment variables.

compie
A: 

to get the home variable of any user, try this hack:

HOME=`sudo -u myuser -s "cd ~; pwd"`
Philipp Keller
A: 

2) Which user's $HOME? root's $HOME or myuser's $HOME

If it's myuser's home, just use $HOME in the child script, and don't use it in the init.d script. This will be set for you by the shell process you are starting. When you do su - {myuser} you are instructing su to run myuser's login shell (as defined in /etc/passwd). The login shell will set the default environment variables based on what shell it is. See your shell's documentation for details. On Solaris this is probably ksh or bourne shell.

3) Do su - myuser -c /usr/bin/env. That will print out the environment variables that will be set in the child script.

Peter Lyons