From owner-freebsd-questions@FreeBSD.ORG Wed Jan 25 16:28:04 2006 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5C10A16A41F for ; Wed, 25 Jan 2006 16:28:04 +0000 (GMT) (envelope-from luke.bakken@gmail.com) Received: from uproxy.gmail.com (uproxy.gmail.com [66.249.92.203]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7353F43D6E for ; Wed, 25 Jan 2006 16:27:56 +0000 (GMT) (envelope-from luke.bakken@gmail.com) Received: by uproxy.gmail.com with SMTP id o2so248536uge for ; Wed, 25 Jan 2006 08:27:55 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=tguX6k8lUfCL7MXV/rouyBKSXHugTjmiRU46QeBXOPL9/sJek1LqxJ6mycC8dB0vt3uGTIde1uPC4ehyT6QYstOWVRwjZN4aomAwtDxA0qd5eAnyqsUWzmfrqxulgJIcfd12QXWdW6xyO1FJf6Ls35/vJxFd4KK5BfF5nKocdks= Received: by 10.49.20.9 with SMTP id x9mr76743nfi; Wed, 25 Jan 2006 08:27:54 -0800 (PST) Received: by 10.49.28.15 with HTTP; Wed, 25 Jan 2006 08:27:54 -0800 (PST) Message-ID: <6acc6ca40601250827l34ed2a08jaf160b94443bff0d@mail.gmail.com> Date: Wed, 25 Jan 2006 08:27:54 -0800 From: Luke Bakken To: Ensel Sharon In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <6acc6ca40601250710x3b0de685j2d7168f6ac5442a0@mail.gmail.com> Cc: freebsd-questions@freebsd.org Subject: Re: shell scripting question (mdconfig device choosing) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Jan 2006 16:28:04 -0000 > > > Thank you very much - you got no output because you have no md device= s in > > > use. I have a few in use and this is the output I get: > > > > > > # mdconfig -l > > > md3 md2 md1 md0 > > > > > > But I could just as easily get: > > > > > > # mdconfig -l > > > md9 md8 md5 md3 > > > > > > Hmm...I just saw that that line is in perl, and I do not have perl > > > installed on any of my 6.0 machines ... I am not sure I want to insta= ll it > > > just for this one shell script :( > > > > Whoops, I forgot that perl isn't in the base any more. What scripting > > languages do you have? If you only have sh, I'll work on that, but it > > won't be a one-liner most likely. Or a C program. > > > I am putting this into a larger, already written /bin/sh program > ... doesn't need to be one line ... > > Wow - thanks a lot for your help. OK, this works on my cygwin install and I think it's generic enough sh programming it should work for you. You could expand the MDDEV variable to encompass all of the devices you could have, past md9. I read the mdconfig man page and it doesn't seem to have an option to list all potential devices. You'll also have to change 'echo $DEV' to whatever means you want to use to return the device from the function. It's not the most elegant solution, but it works. #!/bin/sh function find_first_mdevice { MDDEV=3D'md0 md1 md2 md3 md4 md5 md6 md7 md8 md9' MDOUT=3D`mdconfig -l` for DEV in $MDDEV do if ! echo $MDOUT | grep -q $DEV then break fi done echo $DEV } find_first_mdevice