我在写一个shell脚本来启动几道工序,我的用户路径是不可用的。因为这些进程需要sudo访问,所以我使用sudo运行shell脚本。但是,当我这样做时,我无法访问我的路径变量。我已经为/etc/profile.d/extra-path.sh添加了一个shell脚本,它为我的用户添加了这些脚本。使用sudo运行shell脚本时,
有人能告诉我应该如何添加这些路径变量,以便可以在sudo中运行的shell脚本中访问它们,或者有没有办法在shell脚本中使用我的用户路径运行命令?
这是我想有工作的脚本:
#!/bin/bash
#start stuff up
nohup mongod
#mongod fails as an unknown command, even though it's part of my path
nohup /cust/env/local/cust/jboss-5.1.0.GA/bin/run.sh -b 0.0.0.0 -Djava.awt.headless=true
#jboss needs access to the JAVA_HOME path variable which
#doesn't exist on the path used in this shell script
看看'男人sudoers',你可以反复折腾'secure_path','env_reset','env_keep','env_check',甚至可能是'exempt_group'。 – Wrikken 2013-04-23 23:43:08