当一个接口出现时,位于 /etc/network/if-up.d 中的每个脚本是否都会运行?

Spi*_*pig 14 networking linux ubuntu

启动网络接口时,/etc/network/if-up.d 中的所有脚本是否都运行?

如果是这样,interfaces 文件中的 post-up 命令是什么?

Zor*_*che 16

是的,通常会运行任何标记为可执行文件并放置在该文件夹中的脚本。由于使用了运行部分,因此文件确实仅限于一组特定的名称。

post-up做同样的事情使用up。将脚本放在 if-up.d 中与简单地使用post-up指向其他地方的脚本或命令的a 相同。通常,当您只需要为单个界面运行单个命令时,您会使用 up|post-up。当您有更复杂的事情时,您将创建一个脚本。

人机界面

...
up command

post-up command
      Run  command  after  bringing the interface up.  If this command
      fails then ifup aborts, refraining from marking the interface as
      configured  (even  though it has really been configured), prints
      an error message, and exits with status 0.   This  behavior  may
      change in the future.
...
There  exists  for  each  of  the  above  mentioned options a directory
/etc/network/if-<option>.d/ the scripts in which are run (with no argu-
ments) using run-parts(8) after the option itself has been processed.
Run Code Online (Sandbox Code Playgroud)

人跑零件

run-parts  runs  all  the  executable  files  named  within constraints
described below,

If  the  --lsbsysinit  option  is not given then the names must consist
entirely of upper and lower  case  letters,  digits,  underscores,  and
hyphens.
...
Files are run in the lexical sort  order  of  their  names  unless  the
--reverse  option  is given, in which case they are run in the opposite
order.
Run Code Online (Sandbox Code Playgroud)

  • 这么好的详细答案。即使 10 年后,仍然提供洞察力。 (2认同)
  • 您确实必须彻底阅读 run-parts 手册页才能认识到,即使文件名正确且使用 .sh 扩展名的脚本也不会运行。引用:“......如果有任何关于由于点而跳过脚本的信息,那将会有很大帮助。我花了很多时间进行故障排除......语句'......名称必须完全由大写和小写组成字母、数字、下划线和连字符。还不够。我读了两遍,它并没有帮助我理解我的问题出在哪里。应该明确写出带有点的脚本被跳过。” (2认同)