Re: Help with a Bash script

2010-04-09 Thread Michael Thompson
Just did, sort of still stuck in windows land, with command per line :)

On 9 April 2010 16:18, Bruce Korb  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


Re: Help with a Bash script

2010-04-09 Thread Bruce Korb
> 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


Re: Help with a Bash script

2010-04-08 Thread Cameron Simpson
On 08Apr2010 16:43, Michael Thompson  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
| > 
| > . 
| > 
| > 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  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


Re: Help with a Bash script

2010-04-08 Thread Kevin Martin

>> 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+1rx68clKgoaaLi4AFPxY4C10a/9O
> GYXojPqxSl5gOMYld8Y5eQ0nEqmo7o50hO4Pg2JOlnumunWTTpRsZfZFm8Jjpd48
> dGz/stP117x9U+qALB+WjVcPdqX48+hK/ifky5Inofrs8YKOJdxT7ghO5GaOyJx1
> 5tmCgV7+avOcISdVjkSjvIQ2QQOWQ69+ZM7kjHB84e7tms3KaUMl0UrtNVoxG7QV
> Ci4ISwExK9PZGoHbmon6o2dGuq9hwuDfJ8RmvBRy0Sm5AAqN2pQhrUC2cq9VEeQ=
> =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


Re: Help with a Bash script

2010-04-08 Thread Michael Thompson
-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
> 
> . 
> 
> 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+1rx68clKgoaaLi4AFPxY4C10a/9O
GYXojPqxSl5gOMYld8Y5eQ0nEqmo7o50hO4Pg2JOlnumunWTTpRsZfZFm8Jjpd48
dGz/stP117x9U+qALB+WjVcPdqX48+hK/ifky5Inofrs8YKOJdxT7ghO5GaOyJx1
5tmCgV7+avOcISdVjkSjvIQ2QQOWQ69+ZM7kjHB84e7tms3KaUMl0UrtNVoxG7QV
Ci4ISwExK9PZGoHbmon6o2dGuq9hwuDfJ8RmvBRy0Sm5AAqN2pQhrUC2cq9VEeQ=
=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


Re: Help with a Bash script

2010-04-08 Thread Adalbert Prokop
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

. 

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


Re: Help with a Bash script

2010-04-08 Thread Michael Thompson
-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/

iQEcBAEBAgAGBQJLvfYCAAoJEEcwpNahApVBx7MIALEvkNGKvazDnclBvp7sLGHl
BAz0cSPwRkuBRCip6GiInfm9OVtFw+3fCbByCV70tN4tg9i1D7f2Roaj7NAtCBw6
o65L1BBo+b1JEvvdIQo58PzNKJYfVGG8ZX55SyXoHHPG5SZRiNokzR0lM92U1xOa
i+gBH2Dsl3UxYda3qeQnnkCD+qgITUkKgqrjbxDPfDtBmnmo43tiplbdYjH4XDor
ox4qfdfsTHREUoB6/jCQTlp3tVnbYBLvY+PRpLRAUATjl010IZggEIkLVTsAnPqC
7vg4X2hED9C80jlyZ6EqSDaYhvP3nlZqPLLh1AYwwEdzEX1XynjuYyHNz9qpJsI=
=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


Help with a Bash script

2010-04-08 Thread Michael Thompson
-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/

iQEcBAEBAgAGBQJLvfD5AAoJEEcwpNahApVBDB0IAICTmuZu16K/1P14lUeG4NKP
Sg07LgM1qYW3JLDjVrBnfJ8CE7qtmTwx4GB6WjiNthbJ1LLDmOyg8tQ11sgYKG7E
grOSSSKXXy37bKV4UtPStQgkTUu4UVGNjd6L7/8KlG0YLk9jgSbcSzO0svke/9eP
oYgiz4brRm+MAtHVDDefqrKfJe2bO9B8F1WXRJqDLMIlvHJAP2Rvc36xdGOlAtRT
WS8UVrso2yLjAAm2QK2P3gVvPBe6YlC+1buLyb2/kyRngg9FIZbq6pP8QevwHK6T
8yoWKecPTlrom8xU+1Gj3njcUOqwBDvpv4Rc2WQAw+adnPTU9XwgN/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