linux – 如何在shell脚本中包含目录中的所有文件(在本例中为/et
发布时间:2020-12-13 18:07:32 所属栏目:Linux 来源:网络整理
导读:我在不同的ubuntu服务器上有一个/etc/init.d/iptables start | stop | restart脚本(这是一个普通的 shell脚本) 对于每个新服务,我必须编辑并插入一行来打开一个端口.这导致在不同的机器上有许多不同版本的init.d脚本. 是否可以自动包含让我们说/etc/iptables
我在不同的ubuntu服务器上有一个/etc/init.d/iptables start | stop | restart脚本(这是一个普通的
shell脚本)
对于每个新服务,我必须编辑并插入一行来打开一个端口.这导致在不同的机器上有许多不同版本的init.d脚本. 是否可以自动包含让我们说/etc/iptables/include.d/中的所有文件? 目标是/etc/init.d/iptables的启动函数中只应该有一行代码 include /etc/iptables/include.d/* 在/etc/iptables/include.d/中添加了一个额外的文件后,我只想说 /etc/init.d/iptables restart 编辑:正如Saurabh所指出的那样,当命令需要某个命令时,这会导致问题.高级设置可能有不同的目录,如: /etc/iptables/include01.d/ /etc/iptables/include02.d/ /etc/iptables/include03.d/ 包括他们像这样: include /etc/iptables/include01.d/* ... maybe some code goes here in the main file... include /etc/iptables/include02.d/* include /etc/iptables/include03.d/* 解决方法
将以下行添加到init.d脚本中.
run-parts --report /etc/iptables/include.d 它将作为shell脚本运行目录中的所有内容(需要可执行). 如果您只想执行以.port结尾的文件,您可以使用某些东西 run-parts --regex '.port$' /etc/iptables/include.d/ 如果您想确保订单正确,可以为文件命名: 10_web.port 20_ssh.port etc.. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |