嘿,我有这个问题,在启动时从rc.local启动的脚本没有在启动时设置的环境variables(在/etc/profile.d/*中定义)。 我该怎么办 ?
“su – lisak -c /opt/atlassian-jira-enterprise-4.1.1-standalone/bin/startup.sh”
“su – lisak -c /opt/aaa2/at-22/bin/startup.sh”
/etc/profile.d/*
中的脚本是在它们自己的shell中执行的,而不是源代码,所以它们设置的环境variables是不可用的。你需要什么variables?你可以使用 /etc/environment
吗?你可以用相应的脚本将variables写入一个 var=value
格式的文件中,然后在rc.local
脚本中input这个文件?
这是来自Bash手册页。 您可能会发现它有帮助。
当bash以非交互方式启动时,为了运行一个shell脚本,例如,它在环境中查找variablesBASH_ENV,如果它出现在那里,则展开它的值,并且使用展开的值作为文件的名字来读取和执行。 Bash的行为就像下面的命令执行一样:if [-n“$ BASH_ENV”]; 然后 。 “$ BASH_ENV”; fi但是PATHvariables的值不用于search文件名。
Bourne shell同样使用ENV
variables。
从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.
在你的例子中,你没有指定 – 作为最后的su选项。 尝试这样做或使用一个备用的参数。
我认为最好的解决scheme是源/etc/profile.d/*.sh或从rc.local运行/ etc / profile因为我不想复制从loginshell启动的启动时间脚本和脚本的configuration…
注意:我不知道从rc.local运行/ etc / profile会产生什么后果……所以最好的办法是从/etc/profile.d/*.sh在rc.local中find它们
AKA:用于/etc/profile.d/*中的文件; 做源文件; DONE
替代方法:echo“./etc/profile”>> $ HOME / .bashrc – 对于单个用户