From owner-freebsd-hackers@FreeBSD.ORG Wed Feb 10 17:09:46 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 3377D106566B for ; Wed, 10 Feb 2010 17:09:46 +0000 (UTC) (envelope-from yanefbsd@gmail.com) Received: from mail-qy0-f189.google.com (mail-qy0-f189.google.com [209.85.221.189]) by mx1.freebsd.org (Postfix) with ESMTP id DCEDA8FC1C for ; Wed, 10 Feb 2010 17:09:45 +0000 (UTC) Received: by qyk27 with SMTP id 27so209962qyk.3 for ; Wed, 10 Feb 2010 09:09:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=jr+7ukGaEJyibXfoxz1U8Uo+CTq2GJSjwySY4pRXMBM=; b=OkM02YlosqAYU6EWwzip6gOhPLa7yyyJNSefI9lYS6wUjtAZBNP0hqPBL6gMFFsmQd oZhJ2QZ2I9VWpznJ+4UKwTAkeNWEqne3DIaUiKTBuyd7KBCCFMRWSWwyQed22/DibWpC bqy2qV0VuPEzoCH5UqZNL6R4uQtagy98k0RrA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=BgrXoelPd75goerMeCbTIaC4DUEGaqcRrE/g7Mqm+gG03eUzKhqcDMLWGZtQRTITsg nJgkoiiHYHFMlJLITVtlawkrtR6aj9Sn1ekR4Lc4UYXaz7UBVYfiBi3WBXXXHY+Nlw/P YBeCREoMU7YTDQ8KQX/CYhS7XTvuS5VUoQBnA= MIME-Version: 1.0 Received: by 10.142.61.40 with SMTP id j40mr321473wfa.115.1265821784331; Wed, 10 Feb 2010 09:09:44 -0800 (PST) In-Reply-To: <201002101051.o1AApf85055651@lurza.secnetix.de> References: <201002101051.o1AApf85055651@lurza.secnetix.de> Date: Wed, 10 Feb 2010 09:09:44 -0800 Message-ID: <7d6fde3d1002100909g4b2817bamcd4542601494cc8d@mail.gmail.com> From: Garrett Cooper To: freebsd-hackers@freebsd.org, brampton+freebsd@gmail.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Subject: Re: sysctl with regex? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list 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 17:09:46 -0000 On Wed, Feb 10, 2010 at 2:51 AM, Oliver Fromme 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