Date: Wed, 10 Feb 2010 11:51:41 +0100 (CET) From: Oliver Fromme <olli@lurza.secnetix.de> To: freebsd-hackers@FreeBSD.ORG, brampton+freebsd@gmail.com Subject: Re: sysctl with regex? Message-ID: <201002101051.o1AApf85055651@lurza.secnetix.de> In-Reply-To: <d41814901002091308s7e894b55p880bde165bbbe703@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201002101051.o1AApf85055651>