如何让sudo -E
真正保护环境。假设我有一个
pre-down python /usr/local/myscripts/pre_down.py
在我的/etc/network/interfaces with
/ usr / local / myscripts / pre_down.py`中
import a
和/home/user/scripts/a.py
print 'a'
和/home/user/scripts/__init__.py
存在,为什么sudo PYTHONPATH=/home/user/scripts ifdown eth1
导致
Traceback (most recent call last):
File "/usr/local/myscripts/pre_down.py", line 1, in <module>
import a
ImportError: No module named a
?我知道编写一个sh脚本作为包装器可以解决问题(尝试并成功使用内容PYTHONPATH=/home/user/scripts /usr/local/myscripts/pre_down.py
),以及在import语句之前操作sys.path
。我要求学习:)
答案 0 :(得分:0)
interfaces
个man-page个州:
All of these commands have access to the following environment variables.
IFACE physical name of the interface being processed
LOGICAL
logical name of the interface being processed
ADDRFAM
address family of the interface
METHOD method of the interface (e.g., static)
MODE start if run from ifup, stop if run from ifdown
PHASE as per MODE, but with finer granularity, distinguishing the pre-up, post-up, pre-down and post-down phases.
VERBOSITY
indicates whether --verbose was used; set to 1 if so, 0 if not.
PATH the command search path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Additionally, all options given in an interface definition stanza are exported
to the environment in upper case with "IF_" prepended and with hyphens
converted to underscores and non-alphanumeric characters discarded.
所以看起来这些脚本不会继承命令ifup
或ifdown