FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Fedora User

 
 
LinkBack Thread Tools
 
Old 04-08-2010, 03:06 PM
Michael Thompson
 
Default Help with a Bash script

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I'm quite new to Bash scripting, and just need a little pointer on how
to go through a file, and execute commands there in until the end of the
file is reached.

The idea is this, a list of iptables rules is downloaded, they are run
through a set of commands to get the file in a state ready to run. I
need to read each line of that file, and execute each one. I'm not sure
on loops in bash, and hope someone can help...

I download this file:
http://www.okean.com/antispam/iptables/rc.firewall.china

Then run it through this to sanitize it
sed 's/--dport 25//g' rc.firewall.china|cat|grep "^[ ]*iptables" >
rc.firewall.china_mod

Now, how do I loop through that file executing each line in a for while
loop?

- --
Michael
http://maverickapollo.wordpress.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJLvfD5AAoJEEcwpNahApVBDB0IAICTmuZu16 K/1P14lUeG4NKP
Sg07LgM1qYW3JLDjVrBnfJ8CE7qtmTwx4GB6WjiNthbJ1LLDmO yg8tQ11sgYKG7E
grOSSSKXXy37bKV4UtPStQgkTUu4UVGNjd6L7/8KlG0YLk9jgSbcSzO0svke/9eP
oYgiz4brRm+MAtHVDDefqrKfJe2bO9B8F1WXRJqDLMIlvHJAP2 Rvc36xdGOlAtRT
WS8UVrso2yLjAAm2QK2P3gVvPBe6YlC+1buLyb2/kyRngg9FIZbq6pP8QevwHK6T
8yoWKecPTlrom8xU+1Gj3njcUOqwBDvpv4Rc2WQAw+adnPTU9X wgN/jMb17A4Mc=
=pjO5
-----END PGP SIGNATURE-----
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
 
Old 04-08-2010, 03:28 PM
Michael Thompson
 
Default Help with a Bash script

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 08/04/10 16:06, Michael Thompson wrote:
> I'm quite new to Bash scripting, and just need a little pointer on how
> to go through a file, and execute commands there in until the end of the
> file is reached.
>
> The idea is this, a list of iptables rules is downloaded, they are run
> through a set of commands to get the file in a state ready to run. I
> need to read each line of that file, and execute each one. I'm not sure
> on loops in bash, and hope someone can help...
>
> I download this file:
> http://www.okean.com/antispam/iptables/rc.firewall.china
>
> Then run it through this to sanitize it
> sed 's/--dport 25//g' rc.firewall.china|cat|grep "^[ ]*iptables" >
> rc.firewall.china_mod
>
> Now, how do I loop through that file executing each line in a for while
> loop?
>

Sorted.

#!/bin/bash
wget http://www.okean.com/antispam/iptables/rc.firewall.china
sed 's/--dport 25//g' rc.firewall.china|cat|grep "^[ ]*iptables"|sed
's/INPUT/China/g' > rc.firewall.china_mod
chmod +x rc.firewall.china_mod
./rc.firewall.china_mod

- --
Michael
http://maverickapollo.wordpress.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJLvfYCAAoJEEcwpNahApVBx7MIALEvkNGKva zDnclBvp7sLGHl
BAz0cSPwRkuBRCip6GiInfm9OVtFw+3fCbByCV70tN4tg9i1D7 f2Roaj7NAtCBw6
o65L1BBo+b1JEvvdIQo58PzNKJYfVGG8ZX55SyXoHHPG5SZRiN okzR0lM92U1xOa
i+gBH2Dsl3UxYda3qeQnnkCD+qgITUkKgqrjbxDPfDtBmnmo43 tiplbdYjH4XDor
ox4qfdfsTHREUoB6/jCQTlp3tVnbYBLvY+PRpLRAUATjl010IZggEIkLVTsAnPqC
7vg4X2hED9C80jlyZ6EqSDaYhvP3nlZqPLLh1AYwwEdzEX1Xyn juYyHNz9qpJsI=
=3O0e
-----END PGP SIGNATURE-----
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
 
Old 04-08-2010, 03:29 PM
Adalbert Prokop
 
Default Help with a Bash script

Am 08.04.2010 17:06, schrieb Michael Thompson:

Hi!

> I'm quite new to Bash scripting, and just need a little pointer on how
> to go through a file, and execute commands there in until the end of the
> file is reached.

Well, if your list of commands already is a script, then including it
would be the most convenient method.

Let's say your list is called "script" then

. <path_to_script>

would do it...

In other case here is a small executor script which reads your file line
by line and executes it:

#!/bin/bash
# file: executor
while read line; do
echo Executing: "$line"
eval "$line"
done < "$1"

If you start the executor with your file as the first parameter, it will
execute the lines one by one.

# ./executor script

--
bye
Adalbert
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
 
Old 04-08-2010, 03:43 PM
Michael Thompson
 
Default Help with a Bash script

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 08/04/10 16:29, Adalbert Prokop wrote:
> Am 08.04.2010 17:06, schrieb Michael Thompson:
>
> Hi!

>
> Well, if your list of commands already is a script, then including it
> would be the most convenient method.
>
> Let's say your list is called "script" then
>
> . <path_to_script>
>
> would do it...

Thats exactly the thought I came up with after sending the mail.

>
> In other case here is a small executor script which reads your file line
> by line and executes it:
>
> #!/bin/bash
> # file: executor
> while read line; do
> echo Executing: "$line"
> eval "$line"
> done < "$1"

Thats exactly what I needed.

>
> If you start the executor with your file as the first parameter, it will
> execute the lines one by one.
>
> # ./executor script
>

Many thanks for your help there, much appreciated.

- --
Michael
http://maverickapollo.wordpress.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJLvfmeAAoJEEcwpNahApVBDs4H/04yGl12sLBb95inPW6yuJdg
r867BkHyttZv4EIF8uZVxNVf0LSe9yj4cqr+1rx68clKgoaaLi 4AFPxY4C10a/9O
GYXojPqxSl5gOMYld8Y5eQ0nEqmo7o50hO4Pg2JOlnumunWTTp RsZfZFm8Jjpd48
dGz/stP117x9U+qALB+WjVcPdqX48+hK/ifky5Inofrs8YKOJdxT7ghO5GaOyJx1
5tmCgV7+avOcISdVjkSjvIQ2QQOWQ69+ZM7kjHB84e7tms3KaU Ml0UrtNVoxG7QV
Ci4ISwExK9PZGoHbmon6o2dGuq9hwuDfJ8RmvBRy0Sm5AAqN2p QhrUC2cq9VEeQ=
=uf/v
-----END PGP SIGNATURE-----
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
 
Old 04-08-2010, 04:44 PM
Kevin Martin
 
Default Help with a Bash script

>> If you start the executor with your file as the first parameter, it will
>> execute the lines one by one.
>>
>> # ./executor script
>>
>>
> Many thanks for your help there, much appreciated.
>
> - --
> Michael
> http://maverickapollo.wordpress.com
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/
>
> iQEcBAEBAgAGBQJLvfmeAAoJEEcwpNahApVBDs4H/04yGl12sLBb95inPW6yuJdg
> r867BkHyttZv4EIF8uZVxNVf0LSe9yj4cqr+1rx68clKgoaaLi 4AFPxY4C10a/9O
> GYXojPqxSl5gOMYld8Y5eQ0nEqmo7o50hO4Pg2JOlnumunWTTp RsZfZFm8Jjpd48
> dGz/stP117x9U+qALB+WjVcPdqX48+hK/ifky5Inofrs8YKOJdxT7ghO5GaOyJx1
> 5tmCgV7+avOcISdVjkSjvIQ2QQOWQ69+ZM7kjHB84e7tms3KaU Ml0UrtNVoxG7QV
> Ci4ISwExK9PZGoHbmon6o2dGuq9hwuDfJ8RmvBRy0Sm5AAqN2p QhrUC2cq9VEeQ=
> =uf/v
> -----END PGP SIGNATURE-----
>

It dawns on me that if you are attempting to block all traffic from
those china addresses that you should also remove the "-p tcp" part of
the rules so that everything coming from those addresses is blocked, not
just tcp traffic.

Kevin
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
 
Old 04-09-2010, 01:06 AM
Cameron Simpson
 
Default Help with a Bash script

On 08Apr2010 16:43, Michael Thompson <maverickapollo@googlemail.com> wrote:
| -----BEGIN PGP SIGNED MESSAGE-----
| Hash: SHA1
|
| On 08/04/10 16:29, Adalbert Prokop wrote:
| > Am 08.04.2010 17:06, schrieb Michael Thompson:
| >
| > Hi!
|
| >
| > Well, if your list of commands already is a script, then including it
| > would be the most convenient method.
| >
| > Let's say your list is called "script" then
| >
| > . <path_to_script>
| >
| > would do it...
|
| Thats exactly the thought I came up with after sending the mail.

Had you considered avoiding the intermediate file altogether and going:

sed ... | other changes ... | sh

Saves a huge amount of mucking around.
--
Cameron Simpson <cs@zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

As soon as we started programming, we found to our surprise that it wasn't as
easy to get programs right as we had thought. Debugging had to be discovered.
I can remember the exact instant when I realized that a large part of my life
from then on was going to be spent in finding mistakes in my own programs.
- Maurice Wilkes discovers debugging, 1949
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
 
Old 04-09-2010, 03:18 PM
Bruce Korb
 
Default Help with a Bash script

> Had you considered avoiding the intermediate file altogether and going:
>
> *sed ... | other changes ... | sh

eval "$(sed ... | whatever)"
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
 
Old 04-09-2010, 05:56 PM
Michael Thompson
 
Default Help with a Bash script

Just did, sort of still stuck in windows land, with command per line

On 9 April 2010 16:18, Bruce Korb <bkorb@gnu.org> wrote:
>> Had you considered avoiding the intermediate file altogether and going:
>>
>> *sed ... | other changes ... | sh
>
> eval "$(sed ... | whatever)"
> --
> users mailing list
> users@lists.fedoraproject.org
> To unsubscribe or change subscription options:
> https://admin.fedoraproject.org/mailman/listinfo/users
> Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
>



--
Michael
http://maverickapollo.wordpress.com

To see a World in a Grain of Sand
And a Heaven in a Wild Flower,
Hold Infinity in the palm of your hand
And Eternity in an hour.
--William Blake
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
 

Thread Tools




All times are GMT. The time now is 09:21 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org