Re: help with sh script

2005-07-04 Thread FreeBSD questions mailing list


On 03 jul 2005, at 19:03, fbsd_user wrote:


On Sun, 3 Jul 2005 12:14:05 -0400
"fbsd_user" <[EMAIL PROTECTED]> wrote:



Thanks but I need a little more help.

num_ip="(printf $raw_ip | sed 's/\.//g')"

gives me a error.

What would the correct syntax be?

I am trying to write script to insert rules into PF firewall
on 5.4. using pf anchors.




Hello,

The problem here is that

num_ip="(printf $raw_ip | sed 's/\.//g')"

makes num_ip equal to

(printf $raw_ip | sed 's/\.//g')

instead of its output.

To assign the output of a command use "`":

num_ip=`(printf $raw_ip | sed 's/\.//g')`

Also the subshell (the "()") is not needed:

num_ip=`printf $raw_ip | sed 's/\.//g'`

Hope that helps.

Best Regards,
Ale




Thanks that was just what I needed. Now building on that I tried
this

std_text='No ALTQ support in kernel ALTQ related functions disabled'

ret_ob=`(echo $outrule) | pfctl -a doorman_ob:$session_name_ob -f -
2>&1`
ret_ob=`printf $ret_ob | sed 's/\$std_text//g'`

The goal here is to remove the std_text from the output of the
pftctl command.

I get this error "printf missing format character"

Does sed need different syntax or have I got it all wrong?



printf needs " surrounding the arguments:

printf "$ret_ob"

is the right syntax...

Arno
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: help with sh script

2005-07-04 Thread Roland Smith
On Sun, Jul 03, 2005 at 01:03:40PM -0400, fbsd_user wrote:
> 
> I get this error "printf missing format character"
> 
> Does sed need different syntax or have I got it all wrong?

Issue the following command and be enlightend:

man 1 printf

Or just use 'echo' instead.

Roland
-- 
R.F.Smith (http://www.xs4all.nl/~rsmith/) Please send e-mail as plain text.
public key: http://www.xs4all.nl/~rsmith/pubkey.txt


pgp6WWWemkY7Y.pgp
Description: PGP signature


Re: help with sh script

2005-07-03 Thread Giorgos Keramidas
On 2005-07-03 09:39, fbsd_user <[EMAIL PROTECTED]> wrote:
> What is the sh coding to strip the periods from a IP address??
>
> raw_ip='10.0.10.5'  this is starting
> num_ip='100105'and this is what I need to convert to.

There are many ways:

echo "${raw_ip}" | sed -e 's/\.//g'
echo "${raw_ip}" | perl -pe 's/\.//g'
echo "${raw_ip}" | awk -F. '{gsub("\\.", ""); print}'

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: help with sh script

2005-07-03 Thread Alejandro Pulver
On Sun, 3 Jul 2005 14:59:32 -0400
"fbsd_user" <[EMAIL PROTECTED]> wrote:

> 
> 
> std_text='No ALTQ support in kernel ALTQ related functions disabled'
> ret_ob='No ALTQ support in kernel ALTQ related functions disabled
> OK'
> 
> ret_ob=`printf "$ret_ob" | sed 's/\$std_text//g'`
> Does not strip off the std_text stuff.
> 
> How would I code a statement to remove everything from $ret_ob
> but the ok at the end so $ret_ob would only contain the ok??
> 
> Some times $ret_ob will end in some error message and that is
> what I want to capture after striping off the std_text.
> 
> 
> Thanks
> 


Hello,

The problem here is that single quotes ("'") avoid variable
substitution. e.g.

var="text"
echo $var   # outputs text
echo '$var' # outputs $var (literally)

Also the backslash avoids variable substitution when placed before a
"$". e.g.

echo $var   # outputs text
echo \$var  # outputs $var (literally)

The solution is this:

ret_ob=`printf "$ret_ob" | sed "s/$std_text//g"`
   ^  ^   ^

Hope that helps.

Best Regards,
Ale
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: help with sh script

2005-07-03 Thread FreeBSD questions mailing list


On 03 jul 2005, at 20:59, fbsd_user wrote:




std_text='No ALTQ support in kernel ALTQ related functions disabled'
ret_ob='No ALTQ support in kernel ALTQ related functions disabled
OK'

ret_ob=`printf "$ret_ob" | sed 's/\$std_text//g'`
Does not strip off the std_text stuff.

How would I code a statement to remove everything from $ret_ob
but the ok at the end so $ret_ob would only contain the ok??

Some times $ret_ob will end in some error message and that is
what I want to capture after striping off the std_text.


Thanks


hmm try this then:

ret_ob=`printf "$ret_ob" | tr -d "$std_text"`

Arno
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


RE: help with sh script

2005-07-03 Thread fbsd_user


std_text='No ALTQ support in kernel ALTQ related functions disabled'
ret_ob='No ALTQ support in kernel ALTQ related functions disabled
OK'

ret_ob=`printf "$ret_ob" | sed 's/\$std_text//g'`
Does not strip off the std_text stuff.

How would I code a statement to remove everything from $ret_ob
but the ok at the end so $ret_ob would only contain the ok??

Some times $ret_ob will end in some error message and that is
what I want to capture after striping off the std_text.


Thanks

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: help with sh script

2005-07-03 Thread FreeBSD questions mailing list


On 03 jul 2005, at 17:18, fbsd_user wrote:




On 03 jul 2005, at 15:39, fbsd_user wrote:



What is the sh coding to strip the periods from a IP address??


raw_ip='10.0.10.5'  this is starting
num_ip='100105'and this is what I need to convert to.





Hi,
many ways, here's one:

printf '10.0.10.5' | sed 's/\.//g'

Arno



*

Thanks but I need a little more help.

num_ip="(printf $raw_ip | sed 's/\.//g')"

gives me a error.

What would the correct syntax be?

I am trying to write script to insert rules into PF firewall
on 5.4. using pf anchors.






you forgot the " " around the printf argument:

num_ip=" `printf "$raw_ip" | sed 's/\.//g' ` "


Arno

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


RE: help with sh script

2005-07-03 Thread fbsd_user
On Sun, 3 Jul 2005 12:14:05 -0400
"fbsd_user" <[EMAIL PROTECTED]> wrote:

>> Thanks but I need a little more help.
>>
>> num_ip="(printf $raw_ip | sed 's/\.//g')"
>>
>> gives me a error.
>>
>> What would the correct syntax be?
>>
>> I am trying to write script to insert rules into PF firewall
>> on 5.4. using pf anchors.
>>
>
>Hello,
>
>The problem here is that
>
>num_ip="(printf $raw_ip | sed 's/\.//g')"
>
>makes num_ip equal to
>
>(printf $raw_ip | sed 's/\.//g')
>
>instead of its output.
>
>To assign the output of a command use "`":
>
>num_ip=`(printf $raw_ip | sed 's/\.//g')`
>
>Also the subshell (the "()") is not needed:
>
>num_ip=`printf $raw_ip | sed 's/\.//g'`
>
>Hope that helps.
>
>Best Regards,
>Ale


Thanks that was just what I needed. Now building on that I tried
this

std_text='No ALTQ support in kernel ALTQ related functions disabled'

ret_ob=`(echo $outrule) | pfctl -a doorman_ob:$session_name_ob -f -
2>&1`
ret_ob=`printf $ret_ob | sed 's/\$std_text//g'`

The goal here is to remove the std_text from the output of the
pftctl command.

I get this error "printf missing format character"

Does sed need different syntax or have I got it all wrong?







___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: help with sh script

2005-07-03 Thread Roland Smith
On Sun, Jul 03, 2005 at 12:14:05PM -0400, fbsd_user wrote:
> >many ways, here's one:
> >
> >printf '10.0.10.5' | sed 's/\.//g'
> >
> >Arno
> 
> *
> 
> Thanks but I need a little more help.
> 
> num_ip="(printf $raw_ip | sed 's/\.//g')"
> 
> gives me a error.
> 
> What would the correct syntax be?

Use backtics:

num_ip=`echo $raw_ip | sed 's/\.//g'`

Note that when you do this, more that one IP address can end up as the
same num_ip, e.g. 11.0.1.50 and 1.10.1.50.

Roland
-- 
R.F.Smith (http://www.xs4all.nl/~rsmith/) Please send e-mail as plain text.
public key: http://www.xs4all.nl/~rsmith/pubkey.txt


pgpuorOMrgxpE.pgp
Description: PGP signature


Re: help with sh script

2005-07-03 Thread Alejandro Pulver
On Sun, 3 Jul 2005 12:14:05 -0400
"fbsd_user" <[EMAIL PROTECTED]> wrote:

> Thanks but I need a little more help.
> 
> num_ip="(printf $raw_ip | sed 's/\.//g')"
> 
> gives me a error.
> 
> What would the correct syntax be?
> 
> I am trying to write script to insert rules into PF firewall 
> on 5.4. using pf anchors.
> 

Hello,

The problem here is that

num_ip="(printf $raw_ip | sed 's/\.//g')"

makes num_ip equal to

(printf $raw_ip | sed 's/\.//g')

instead of its output.

To assign the output of a command use "`":

num_ip=`(printf $raw_ip | sed 's/\.//g')`

Also the subshell (the "()") is not needed:

num_ip=`printf $raw_ip | sed 's/\.//g'`

Hope that helps.

Best Regards,
Ale
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


RE: help with sh script

2005-07-03 Thread fbsd_user


On 03 jul 2005, at 15:39, fbsd_user wrote:

>> What is the sh coding to strip the periods from a IP address??
>>
>>
>> raw_ip='10.0.10.5'  this is starting
>> num_ip='100105'and this is what I need to convert to.
>>
>>
>>
>Hi,
>many ways, here's one:
>
>printf '10.0.10.5' | sed 's/\.//g'
>
>Arno

*

Thanks but I need a little more help.

num_ip="(printf $raw_ip | sed 's/\.//g')"

gives me a error.

What would the correct syntax be?

I am trying to write script to insert rules into PF firewall 
on 5.4. using pf anchors.


___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: help with sh script

2005-07-03 Thread FreeBSD questions mailing list


On 03 jul 2005, at 15:39, fbsd_user wrote:


What is the sh coding to strip the periods from a IP address??


raw_ip='10.0.10.5'  this is starting
num_ip='100105'and this is what I need to convert to.




Hi,
many ways, here's one:

printf '10.0.10.5' | sed 's/\.//g'

Arno

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


help with sh script

2005-07-03 Thread fbsd_user
What is the sh coding to strip the periods from a IP address??


raw_ip='10.0.10.5'  this is starting
num_ip='100105'and this is what I need to convert to.




thanks in advance
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"