sysctl with regex?
Oliver Fromme
olli at lurza.secnetix.de
Wed Feb 10 10:51:58 UTC 2010
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.
Best regards
Oliver
--
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606, Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758, Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart
FreeBSD-Dienstleistungen, -Produkte und mehr: http://www.secnetix.de/bsd
"Documentation is like sex; when it's good, it's very, very good,
and when it's bad, it's better than nothing."
-- Dick Brandon
More information about the freebsd-hackers
mailing list