On Wed, Feb 10, 2010 at 2:51 AM, Oliver Fromme <o...@lurza.secnetix.de> wrote:
> Andrew Brampton wrote:
>  > Today I was writing a script to read all the dev.cpu.?.temperature
>  > sysctl OIDs. I was parsing them using a simple grep, but it occurred
>  > to me it might be better if sysctl supported some form of regexp. For
>  > example instead of typing:
>  > sysctl -a | grep dev.cpu.*.temperature
>  >
>  > I could write:
>  > sysctl dev.cpu.*.temperature
>  >
>  > which would display all the OIDs that match dev.cpu.*.temperature.
>  > This is better than grep because when I issue a "sysctl -a" the
>  > program retrieves many variables that I am not interested in (which
>  > later get filtered by grep).
>
> I'm not sure such a feature is really necessary.
> What's wrong with this approach?
>
> $ sysctl dev.cpu | grep temperature
>
> When you need that in a script, there's an even more
> elegant way to do it:
>
> NCPU=`sysctl -n hw.ncpu`
> OIDS=`jot -w dev.cpu.%d.temperature $NCPU 0`
> sysctl $OIDS
>
> There's no need to use "sysctl -a".  After all, the
> "UNIX way" of doing things is to combine the existing
> tools instead of duplicate features in many tools.

    True... while I was looking at where to insert the expression
matcher, I couldn't see a single *good* location where to put it
because all of the APIs in sysctl(1) are print or return an OID
integer without thoroughly hacking up the source (even though it is
largely hacked up today from the looks of it).
Ugh.
-Garrett
_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"

Reply via email to