Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 Feb 2010 09:09:44 -0800
From:      Garrett Cooper <yanefbsd@gmail.com>
To:        freebsd-hackers@freebsd.org, brampton+freebsd@gmail.com
Subject:   Re: sysctl with regex?
Message-ID:  <7d6fde3d1002100909g4b2817bamcd4542601494cc8d@mail.gmail.com>
In-Reply-To: <201002101051.o1AApf85055651@lurza.secnetix.de>
References:  <d41814901002091308s7e894b55p880bde165bbbe703@mail.gmail.com> <201002101051.o1AApf85055651@lurza.secnetix.de>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Feb 10, 2010 at 2:51 AM, Oliver Fromme <olli@lurza.secnetix.de> wro=
te:
> Andrew Brampton wrote:
> =A0> Today I was writing a script to read all the dev.cpu.?.temperature
> =A0> sysctl OIDs. I was parsing them using a simple grep, but it occurred
> =A0> to me it might be better if sysctl supported some form of regexp. Fo=
r
> =A0> example instead of typing:
> =A0> sysctl -a | grep dev.cpu.*.temperature
> =A0>
> =A0> I could write:
> =A0> sysctl dev.cpu.*.temperature
> =A0>
> =A0> which would display all the OIDs that match dev.cpu.*.temperature.
> =A0> This is better than grep because when I issue a "sysctl -a" the
> =A0> program retrieves many variables that I am not interested in (which
> =A0> 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=3D`sysctl -n hw.ncpu`
> OIDS=3D`jot -w dev.cpu.%d.temperature $NCPU 0`
> sysctl $OIDS
>
> There's no need to use "sysctl -a". =A0After 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?7d6fde3d1002100909g4b2817bamcd4542601494cc8d>