在/etc/network/interfaces中为预down命令设置PYTHONPATH的位置



我如何使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。我问你是为了学习:)

interfaces的手册说明:

   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.

所以这些脚本似乎没有继承ifupifdown命令的环境

最新更新