How to include all files from a directory in shell script (/etc/init.d/iptables in this case) Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Come Celebrate our 10 Year Anniversary!Is there a way to prevent output from backgrounded tasks from covering the command line in a shell?How to lock user in a shell script program?Call to daemon in a /etc/init.d script is blocking, not running in backgroundchkconfig not starting application script on bootupHow to remove/backup script from /etc/init.d/?Iptables appends rule default after “-A INPUT -j REJECT --reject-with icmp-host-prohibited”How to load the environment variables at boot time before X11 on Ubuntu Precise?How to remove all rules referring to a chain in iptables?How to setup IPTables on KVM host - iptables-persistent is being ignoredLoading iptables rules from /etc/init.d/
Providing direct feedback to a product salesperson
2 sample t test for sample sizes - 30,000 and 150,000
Why does BitLocker not use RSA?
Does traveling In The United States require a passport or can I use my green card if not a US citizen?
Do chord progressions usually move by fifths?
Suing a Police Officer Instead of the Police Department
Determine the generator of an ideal of ring of integers
Kepler's 3rd law: ratios don't fit data
Does using the Inspiration rules for character defects encourage My Guy Syndrome?
"Destructive force" carried by a B-52?
Why not use the yoke to control yaw, as well as pitch and roll?
When does Bran Stark remember Jamie pushing him?
Is "ein Herz wie das meine" an antiquated or colloquial use of the possesive pronoun?
Unix AIX passing variable and arguments to expect and spawn
What is the evidence that custom checks in Northern Ireland are going to result in violence?
Raising a bilingual kid. When should we introduce the majority language?
Short story about an alien named Ushtu(?) coming from a future Earth, when ours was destroyed by a nuclear explosion
Marquee sign letters
What were wait-states, and why was it only an issue for PCs?
Putting Ant-Man on house arrest
Has a Nobel Peace laureate ever been accused of war crimes?
Protagonist's race is hidden - should I reveal it?
Can this water damage be explained by lack of gutters and grading issues?
When speaking, how do you change your mind mid-sentence?
How to include all files from a directory in shell script (/etc/init.d/iptables in this case)
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Come Celebrate our 10 Year Anniversary!Is there a way to prevent output from backgrounded tasks from covering the command line in a shell?How to lock user in a shell script program?Call to daemon in a /etc/init.d script is blocking, not running in backgroundchkconfig not starting application script on bootupHow to remove/backup script from /etc/init.d/?Iptables appends rule default after “-A INPUT -j REJECT --reject-with icmp-host-prohibited”How to load the environment variables at boot time before X11 on Ubuntu Precise?How to remove all rules referring to a chain in iptables?How to setup IPTables on KVM host - iptables-persistent is being ignoredLoading iptables rules from /etc/init.d/
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have an /etc/init.d/iptables start|stop|restart
script on different ubuntu servers (which is a normal shell script)
For each new service I have to edit and insert a line to open a port. This leads to many different versions of the init.d script on different machines.
Is it possible to automatically include let's say all files in /etc/iptables/include.d/
?
The target is that there should only a line in the start function of /etc/init.d/iptables like
include /etc/iptables/include.d/*
And after an additional file in /etc/iptables/include.d/
I'd simply say
/etc/init.d/iptables restart
Edit: As Saurabh pointed out this can lead to problems when commands need a certain order. An advanced setup could have different directories like:
/etc/iptables/include01.d/
/etc/iptables/include02.d/
/etc/iptables/include03.d/
and including them like this:
include /etc/iptables/include01.d/*
... maybe some code goes here in the main file...
include /etc/iptables/include02.d/*
include /etc/iptables/include03.d/*
linux unix bash iptables shell
add a comment |
I have an /etc/init.d/iptables start|stop|restart
script on different ubuntu servers (which is a normal shell script)
For each new service I have to edit and insert a line to open a port. This leads to many different versions of the init.d script on different machines.
Is it possible to automatically include let's say all files in /etc/iptables/include.d/
?
The target is that there should only a line in the start function of /etc/init.d/iptables like
include /etc/iptables/include.d/*
And after an additional file in /etc/iptables/include.d/
I'd simply say
/etc/init.d/iptables restart
Edit: As Saurabh pointed out this can lead to problems when commands need a certain order. An advanced setup could have different directories like:
/etc/iptables/include01.d/
/etc/iptables/include02.d/
/etc/iptables/include03.d/
and including them like this:
include /etc/iptables/include01.d/*
... maybe some code goes here in the main file...
include /etc/iptables/include02.d/*
include /etc/iptables/include03.d/*
linux unix bash iptables shell
add a comment |
I have an /etc/init.d/iptables start|stop|restart
script on different ubuntu servers (which is a normal shell script)
For each new service I have to edit and insert a line to open a port. This leads to many different versions of the init.d script on different machines.
Is it possible to automatically include let's say all files in /etc/iptables/include.d/
?
The target is that there should only a line in the start function of /etc/init.d/iptables like
include /etc/iptables/include.d/*
And after an additional file in /etc/iptables/include.d/
I'd simply say
/etc/init.d/iptables restart
Edit: As Saurabh pointed out this can lead to problems when commands need a certain order. An advanced setup could have different directories like:
/etc/iptables/include01.d/
/etc/iptables/include02.d/
/etc/iptables/include03.d/
and including them like this:
include /etc/iptables/include01.d/*
... maybe some code goes here in the main file...
include /etc/iptables/include02.d/*
include /etc/iptables/include03.d/*
linux unix bash iptables shell
I have an /etc/init.d/iptables start|stop|restart
script on different ubuntu servers (which is a normal shell script)
For each new service I have to edit and insert a line to open a port. This leads to many different versions of the init.d script on different machines.
Is it possible to automatically include let's say all files in /etc/iptables/include.d/
?
The target is that there should only a line in the start function of /etc/init.d/iptables like
include /etc/iptables/include.d/*
And after an additional file in /etc/iptables/include.d/
I'd simply say
/etc/init.d/iptables restart
Edit: As Saurabh pointed out this can lead to problems when commands need a certain order. An advanced setup could have different directories like:
/etc/iptables/include01.d/
/etc/iptables/include02.d/
/etc/iptables/include03.d/
and including them like this:
include /etc/iptables/include01.d/*
... maybe some code goes here in the main file...
include /etc/iptables/include02.d/*
include /etc/iptables/include03.d/*
linux unix bash iptables shell
linux unix bash iptables shell
edited Jul 16 '09 at 10:26
user12096
asked Jul 16 '09 at 9:54
user12096user12096
44741838
44741838
add a comment |
add a comment |
6 Answers
6
active
oldest
votes
Add the following line to your init.d script.
run-parts --report /etc/iptables/include.d
It will run everything in the directory as a shell script (need to be executable).
If you you only want to execute files that ends with .port you could use something
like:
run-parts --regex '.port$' /etc/iptables/include.d/
If you want to make sure the order is correct you can name the files:
10_web.port
20_ssh.port
etc..
add a comment |
for f in /etc/iptables/include.d/*
. $f
done
note space between dot and %f
Saurabh is right - this will not necessary work as you intend, but use some naming convention eg 10-xxx, 20-yyy and so on and it might be manageable.
i think this is great, because i do not rely on an external command (run-parts)
– user12096
Jul 16 '09 at 20:39
will the order of the files when numbered 10-xxx, 20-yyy be respected automatically by thefor f in
?
– user12096
Jul 18 '09 at 10:49
@matnagel - should be. if you have any doubts, replace /etc/iptables/include.d/* withls -1 /etc/iptables/include.d/*.extension
- with ls you can control sorting criteria, default one is by name. notice special quote symbol.
– pQd
Jul 18 '09 at 11:48
add a comment |
You can define simple function in bash:
function include()
for FILE in $( find "$1" -type f -print
and then:
include some_dir/*
or even:
include some_dir/*.conf
this is even better than pQd's solution.
– user12096
Jul 16 '09 at 20:40
add a comment |
You may also consider building the iptables script from template files, one of which would be the original iptables script. create a script which will read your template files in the relevant directories and create a new iptables script from them. That way when you need to make changes you do so in the templates and just rerun your script generator.
Using this method you could even get fancy and place markers in the base template which can be used to signal when to include files from specific directories in your template tree.
add a comment |
I do not think you can include files in iptables configuration. The choice makes sense as firewall rules depend a lot on order in which they are written. If we just include files in folder, iptables wont know which rules to put first and which later.
this is a good point. thank you for pointing this out. i am updating the question to use several include.d directories, so I can give them an order. I have many services that do not depend on each other and the setup would still make sense in these cases.
– user12096
Jul 16 '09 at 10:21
add a comment |
To well behave with empty dir include.d/
you can do:
for f in /etc/iptables/include.d/*; do
[[ -e "$f" ]] && . "$f"
done
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "2"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f41497%2fhow-to-include-all-files-from-a-directory-in-shell-script-etc-init-d-iptables%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
Add the following line to your init.d script.
run-parts --report /etc/iptables/include.d
It will run everything in the directory as a shell script (need to be executable).
If you you only want to execute files that ends with .port you could use something
like:
run-parts --regex '.port$' /etc/iptables/include.d/
If you want to make sure the order is correct you can name the files:
10_web.port
20_ssh.port
etc..
add a comment |
Add the following line to your init.d script.
run-parts --report /etc/iptables/include.d
It will run everything in the directory as a shell script (need to be executable).
If you you only want to execute files that ends with .port you could use something
like:
run-parts --regex '.port$' /etc/iptables/include.d/
If you want to make sure the order is correct you can name the files:
10_web.port
20_ssh.port
etc..
add a comment |
Add the following line to your init.d script.
run-parts --report /etc/iptables/include.d
It will run everything in the directory as a shell script (need to be executable).
If you you only want to execute files that ends with .port you could use something
like:
run-parts --regex '.port$' /etc/iptables/include.d/
If you want to make sure the order is correct you can name the files:
10_web.port
20_ssh.port
etc..
Add the following line to your init.d script.
run-parts --report /etc/iptables/include.d
It will run everything in the directory as a shell script (need to be executable).
If you you only want to execute files that ends with .port you could use something
like:
run-parts --regex '.port$' /etc/iptables/include.d/
If you want to make sure the order is correct you can name the files:
10_web.port
20_ssh.port
etc..
answered Jul 16 '09 at 10:25
rkthkrrkthkr
7,7132136
7,7132136
add a comment |
add a comment |
for f in /etc/iptables/include.d/*
. $f
done
note space between dot and %f
Saurabh is right - this will not necessary work as you intend, but use some naming convention eg 10-xxx, 20-yyy and so on and it might be manageable.
i think this is great, because i do not rely on an external command (run-parts)
– user12096
Jul 16 '09 at 20:39
will the order of the files when numbered 10-xxx, 20-yyy be respected automatically by thefor f in
?
– user12096
Jul 18 '09 at 10:49
@matnagel - should be. if you have any doubts, replace /etc/iptables/include.d/* withls -1 /etc/iptables/include.d/*.extension
- with ls you can control sorting criteria, default one is by name. notice special quote symbol.
– pQd
Jul 18 '09 at 11:48
add a comment |
for f in /etc/iptables/include.d/*
. $f
done
note space between dot and %f
Saurabh is right - this will not necessary work as you intend, but use some naming convention eg 10-xxx, 20-yyy and so on and it might be manageable.
i think this is great, because i do not rely on an external command (run-parts)
– user12096
Jul 16 '09 at 20:39
will the order of the files when numbered 10-xxx, 20-yyy be respected automatically by thefor f in
?
– user12096
Jul 18 '09 at 10:49
@matnagel - should be. if you have any doubts, replace /etc/iptables/include.d/* withls -1 /etc/iptables/include.d/*.extension
- with ls you can control sorting criteria, default one is by name. notice special quote symbol.
– pQd
Jul 18 '09 at 11:48
add a comment |
for f in /etc/iptables/include.d/*
. $f
done
note space between dot and %f
Saurabh is right - this will not necessary work as you intend, but use some naming convention eg 10-xxx, 20-yyy and so on and it might be manageable.
for f in /etc/iptables/include.d/*
. $f
done
note space between dot and %f
Saurabh is right - this will not necessary work as you intend, but use some naming convention eg 10-xxx, 20-yyy and so on and it might be manageable.
answered Jul 16 '09 at 10:18
pQdpQd
25.6k35494
25.6k35494
i think this is great, because i do not rely on an external command (run-parts)
– user12096
Jul 16 '09 at 20:39
will the order of the files when numbered 10-xxx, 20-yyy be respected automatically by thefor f in
?
– user12096
Jul 18 '09 at 10:49
@matnagel - should be. if you have any doubts, replace /etc/iptables/include.d/* withls -1 /etc/iptables/include.d/*.extension
- with ls you can control sorting criteria, default one is by name. notice special quote symbol.
– pQd
Jul 18 '09 at 11:48
add a comment |
i think this is great, because i do not rely on an external command (run-parts)
– user12096
Jul 16 '09 at 20:39
will the order of the files when numbered 10-xxx, 20-yyy be respected automatically by thefor f in
?
– user12096
Jul 18 '09 at 10:49
@matnagel - should be. if you have any doubts, replace /etc/iptables/include.d/* withls -1 /etc/iptables/include.d/*.extension
- with ls you can control sorting criteria, default one is by name. notice special quote symbol.
– pQd
Jul 18 '09 at 11:48
i think this is great, because i do not rely on an external command (run-parts)
– user12096
Jul 16 '09 at 20:39
i think this is great, because i do not rely on an external command (run-parts)
– user12096
Jul 16 '09 at 20:39
will the order of the files when numbered 10-xxx, 20-yyy be respected automatically by the
for f in
?– user12096
Jul 18 '09 at 10:49
will the order of the files when numbered 10-xxx, 20-yyy be respected automatically by the
for f in
?– user12096
Jul 18 '09 at 10:49
@matnagel - should be. if you have any doubts, replace /etc/iptables/include.d/* with
ls -1 /etc/iptables/include.d/*.extension
- with ls you can control sorting criteria, default one is by name. notice special quote symbol.– pQd
Jul 18 '09 at 11:48
@matnagel - should be. if you have any doubts, replace /etc/iptables/include.d/* with
ls -1 /etc/iptables/include.d/*.extension
- with ls you can control sorting criteria, default one is by name. notice special quote symbol.– pQd
Jul 18 '09 at 11:48
add a comment |
You can define simple function in bash:
function include()
for FILE in $( find "$1" -type f -print
and then:
include some_dir/*
or even:
include some_dir/*.conf
this is even better than pQd's solution.
– user12096
Jul 16 '09 at 20:40
add a comment |
You can define simple function in bash:
function include()
for FILE in $( find "$1" -type f -print
and then:
include some_dir/*
or even:
include some_dir/*.conf
this is even better than pQd's solution.
– user12096
Jul 16 '09 at 20:40
add a comment |
You can define simple function in bash:
function include()
for FILE in $( find "$1" -type f -print
and then:
include some_dir/*
or even:
include some_dir/*.conf
You can define simple function in bash:
function include()
for FILE in $( find "$1" -type f -print
and then:
include some_dir/*
or even:
include some_dir/*.conf
answered Jul 16 '09 at 11:40
user13185
this is even better than pQd's solution.
– user12096
Jul 16 '09 at 20:40
add a comment |
this is even better than pQd's solution.
– user12096
Jul 16 '09 at 20:40
this is even better than pQd's solution.
– user12096
Jul 16 '09 at 20:40
this is even better than pQd's solution.
– user12096
Jul 16 '09 at 20:40
add a comment |
You may also consider building the iptables script from template files, one of which would be the original iptables script. create a script which will read your template files in the relevant directories and create a new iptables script from them. That way when you need to make changes you do so in the templates and just rerun your script generator.
Using this method you could even get fancy and place markers in the base template which can be used to signal when to include files from specific directories in your template tree.
add a comment |
You may also consider building the iptables script from template files, one of which would be the original iptables script. create a script which will read your template files in the relevant directories and create a new iptables script from them. That way when you need to make changes you do so in the templates and just rerun your script generator.
Using this method you could even get fancy and place markers in the base template which can be used to signal when to include files from specific directories in your template tree.
add a comment |
You may also consider building the iptables script from template files, one of which would be the original iptables script. create a script which will read your template files in the relevant directories and create a new iptables script from them. That way when you need to make changes you do so in the templates and just rerun your script generator.
Using this method you could even get fancy and place markers in the base template which can be used to signal when to include files from specific directories in your template tree.
You may also consider building the iptables script from template files, one of which would be the original iptables script. create a script which will read your template files in the relevant directories and create a new iptables script from them. That way when you need to make changes you do so in the templates and just rerun your script generator.
Using this method you could even get fancy and place markers in the base template which can be used to signal when to include files from specific directories in your template tree.
answered Jul 16 '09 at 12:44
John GardeniersJohn Gardeniers
25k847105
25k847105
add a comment |
add a comment |
I do not think you can include files in iptables configuration. The choice makes sense as firewall rules depend a lot on order in which they are written. If we just include files in folder, iptables wont know which rules to put first and which later.
this is a good point. thank you for pointing this out. i am updating the question to use several include.d directories, so I can give them an order. I have many services that do not depend on each other and the setup would still make sense in these cases.
– user12096
Jul 16 '09 at 10:21
add a comment |
I do not think you can include files in iptables configuration. The choice makes sense as firewall rules depend a lot on order in which they are written. If we just include files in folder, iptables wont know which rules to put first and which later.
this is a good point. thank you for pointing this out. i am updating the question to use several include.d directories, so I can give them an order. I have many services that do not depend on each other and the setup would still make sense in these cases.
– user12096
Jul 16 '09 at 10:21
add a comment |
I do not think you can include files in iptables configuration. The choice makes sense as firewall rules depend a lot on order in which they are written. If we just include files in folder, iptables wont know which rules to put first and which later.
I do not think you can include files in iptables configuration. The choice makes sense as firewall rules depend a lot on order in which they are written. If we just include files in folder, iptables wont know which rules to put first and which later.
answered Jul 16 '09 at 10:17
Saurabh BarjatiyaSaurabh Barjatiya
4,05712331
4,05712331
this is a good point. thank you for pointing this out. i am updating the question to use several include.d directories, so I can give them an order. I have many services that do not depend on each other and the setup would still make sense in these cases.
– user12096
Jul 16 '09 at 10:21
add a comment |
this is a good point. thank you for pointing this out. i am updating the question to use several include.d directories, so I can give them an order. I have many services that do not depend on each other and the setup would still make sense in these cases.
– user12096
Jul 16 '09 at 10:21
this is a good point. thank you for pointing this out. i am updating the question to use several include.d directories, so I can give them an order. I have many services that do not depend on each other and the setup would still make sense in these cases.
– user12096
Jul 16 '09 at 10:21
this is a good point. thank you for pointing this out. i am updating the question to use several include.d directories, so I can give them an order. I have many services that do not depend on each other and the setup would still make sense in these cases.
– user12096
Jul 16 '09 at 10:21
add a comment |
To well behave with empty dir include.d/
you can do:
for f in /etc/iptables/include.d/*; do
[[ -e "$f" ]] && . "$f"
done
add a comment |
To well behave with empty dir include.d/
you can do:
for f in /etc/iptables/include.d/*; do
[[ -e "$f" ]] && . "$f"
done
add a comment |
To well behave with empty dir include.d/
you can do:
for f in /etc/iptables/include.d/*; do
[[ -e "$f" ]] && . "$f"
done
To well behave with empty dir include.d/
you can do:
for f in /etc/iptables/include.d/*; do
[[ -e "$f" ]] && . "$f"
done
answered Apr 16 at 14:30
keypresskeypress
1666
1666
add a comment |
add a comment |
Thanks for contributing an answer to Server Fault!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f41497%2fhow-to-include-all-files-from-a-directory-in-shell-script-etc-init-d-iptables%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown