On 2013-06-18 19:04, Tim Connors wrote:
[...]
> This seems to be a suitably hacking way of doing it:
> 
> 
> # build an array of all replacements /0../32 to /0.0.0.0 ->
> # /255.255.255.255 so that any occurences can quickly be replaced
> # globally in any required filter
> cidr2netmaskfilter=
> for cidr in `seq 0 32` ; do
>     netmask=`cidr2mask "$cidr"`
>     cidr2netmaskfilter="$cidr2netmaskfilter; s!/$cidr !/$netmask!g"
> done
> 
> function filter_cidr2mask () {
>     sed "$cidr2netmaskfilter"
> }
[...]

Hi Tim,

A couple of pointers: I'd discourage the use of seq[1]. If you're using
bash, which I assume you are given that's available on all RHEL
instances, I'd use {0..32} instead of `seq 0 32`. I also advice using
$(cidr2mask "$cidr") rather than `cidr2mask "$cidr"`; The $() notation
is newer and more predictable, especially with regard to quoting.

Also, what *is* cidr2mask? I've not seen it anywhere before.

Further, your sed appears to be expecting a space after "$cidr", but
isn't putting one back after "$netmask". That could give you grief.

Finally, were I writing this myself (in the absense of cidr2mask), I'd
probably do something like the following:

| filter_cidr2mask(){
|   cidr=(
|   0.0.0.0
|   128.0.0.0
|   192.0.0.0
|   224.0.0.0
|   240.0.0.0
|   248.0.0.0
|   252.0.0.0
|   254.0.0.0
|   255.0.0.0
|   255.128.0.0
|   255.192.0.0
|   255.224.0.0
|   255.240.0.0
|   255.248.0.0
|   255.252.0.0
|   255.254.0.0
|   255.255.0.0
|   255.255.128.0
|   255.255.192.0
|   255.255.224.0
|   255.255.240.0
|   255.255.248.0
|   255.255.252.0
|   255.255.254.0
|   255.255.255.0
|   255.255.255.128
|   255.255.255.192
|   255.255.255.224
|   255.255.255.240
|   255.255.255.248
|   255.255.255.252
|   255.255.255.254
|   255.255.255.255
|   )
|
|   sedExp=
|   for ((i=0; i<=32; i++)); do
|     sedExp+="s!/\<$i\>!/${cidr[$i]}!g; "
|   done
|
|   sed "$sedExp"
| }

1.  <greybot> seq(1) is a highly nonstandard program used to count to 10
              in silly Linux howtos. Use one of these: for ((i = 1; i <=
              10; i++)); do ...  (bash 2.04+/zsh/ksh93), i=; while ((i++
              <= 10)); do ...  (bash/mksh/ksh88), i=; while [ $(( ( i +=
              1 ) <= 10 )) -ne 0 ]; do ...  (POSIX). Don't do this: for
              x in $(...); do ... Don't do this: for i in {1..10}; do
              ...

-- 
Regards,
Matthew Cengia

Attachment: signature.asc
Description: Digital signature

_______________________________________________
luv-main mailing list
[email protected]
http://lists.luv.asn.au/listinfo/luv-main

Reply via email to