From owner-freebsd-questions@FreeBSD.ORG Tue Jan 24 21:56:01 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 0E7FE16A41F for ; Tue, 24 Jan 2006 21:56:01 +0000 (GMT) (envelope-from user@dhp.com) Received: from shell.dhp.com (shell.dhp.com [199.245.105.1]) by mx1.FreeBSD.org (Postfix) with ESMTP id 892DC43D6E for ; Tue, 24 Jan 2006 21:56:00 +0000 (GMT) (envelope-from user@dhp.com) Received: by shell.dhp.com (Postfix, from userid 896) id CE2D6312F5; Tue, 24 Jan 2006 16:55:59 -0500 (EST) Date: Tue, 24 Jan 2006 16:55:59 -0500 (EST) From: Ensel Sharon To: freebsd-questions@freebsd.org Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: 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: Tue, 24 Jan 2006 21:56:01 -0000 Hello, When I mdconfig a device and _do not_ specify a particular numbered md device (with the -u flag), it just chooses an unused device number for me. Which makes me happy. Unfortunately, mdconfig chooses the next available device, from the highest device currently in use, regardless of whether or not there are much lower devices unused. For instance, if I have md0 and md1 in use, mdconfig will auto choose md2. Good. However if I only have md10 and md11 in use, mdconfig will NOT choose md0, it will choose md12. I need it to choose the lowest available unused device. How can I do this in a bit of /bin/sh shell code ? I can check what devices are in use with `mdconfig -l`, like so: # mdconfig -l md0 and I know how to use awk to strip away the leading "md" from each piece of the output ... but I do not know how to take output like: 8 9 11 14 and decide that the lowest available number is "0". How can I do this ? Thank you.