2

Hey, I have this problem, that scripts started at boot time from rc.local don't have environment variables (defined at /etc/profile.d/*) set at the time of their startup. What should I do ?


"su - lisak -c /opt/atlassian-jira-enterprise-4.1.1-standalone/bin/startup.sh"

"su - lisak -c /opt/aaa2/at-22/bin/startup.sh"


lisak
  • 697
  • 2
  • 8
  • 19

3 Answers3

0

The scripts at /etc/profile.d/* are executed in their own shells rather than sourced so the environment variables they set are not available anyway.What variables do you need? Can you make use of /etc/environment? Can you write the variables into a file in a var=value format from the appropriate scripts and source that file in your rc.local scripts?

This is from the Bash man page. You may find it helpful.

When bash is started non-interactively, to run a shell script, for example, it looks for the variable BASH_ENV in the environment, expands its value if it appears there, and uses the expanded value as the name of a file to read and execute. Bash behaves as if the following com‐ mand were executed: if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi but the value of the PATH variable is not used to search for the file name.

The Bourne shell similarly uses the ENV variable.

0

Quote from the su manpage (Slackware 13.1):

       -, -l, --login
       Provide an environment similar to what the user would expect had
       the user logged in directly.

       When - is used, it must be specified as the last su option. The
       other forms (-l and --login) do not have this restriction.

In your example, you don't specify - as the last su option. Try doing that or using an alternate argument.

halp
  • 2,528
0

I think the best solution is to source /etc/profile.d/*.sh or run /etc/profile from rc.local cause I don't want to duplicate configuration for boot time scripts and scripts started from login shell...

NOTE: I don't know what might be the consequences of running /etc/profile from rc.local ...so the best way would be sourcing them at rc.local from /etc/profile.d/*.sh


AKA: for file in /etc/profile.d/*; do source $file; done


ALTERNATIVE: echo ". /etc/profile" >> $HOME/.bashrc - for single user

lisak
  • 697
  • 2
  • 8
  • 19