From owner-freebsd-hackers@FreeBSD.ORG Wed Feb 10 10:51:58 2010 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3E7571065670 for ; Wed, 10 Feb 2010 10:51:58 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (lurza.secnetix.de [IPv6:2a01:170:102f::2]) by mx1.freebsd.org (Postfix) with ESMTP id B97F08FC14 for ; Wed, 10 Feb 2010 10:51:57 +0000 (UTC) Received: from lurza.secnetix.de (localhost [127.0.0.1]) by lurza.secnetix.de (8.14.3/8.14.3) with ESMTP id o1AApfj0055652; Wed, 10 Feb 2010 11:51:56 +0100 (CET) (envelope-from oliver.fromme@secnetix.de) Received: (from olli@localhost) by lurza.secnetix.de (8.14.3/8.14.3/Submit) id o1AApf85055651; Wed, 10 Feb 2010 11:51:41 +0100 (CET) (envelope-from olli) Date: Wed, 10 Feb 2010 11:51:41 +0100 (CET) Message-Id: <201002101051.o1AApf85055651@lurza.secnetix.de> From: Oliver Fromme To: freebsd-hackers@FreeBSD.ORG, brampton+freebsd@gmail.com In-Reply-To: X-Newsgroups: list.freebsd-hackers User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (FreeBSD/6.4-PRERELEASE-20080904 (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.1.2 (lurza.secnetix.de [127.0.0.1]); Wed, 10 Feb 2010 11:51:56 +0100 (CET) Cc: Subject: Re: sysctl with regex? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd-hackers@FreeBSD.ORG, brampton+freebsd@gmail.com List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Feb 2010 10:51:58 -0000 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