shell scripting question (mdconfig device choosing)

Luke Bakken luke.bakken at gmail.com
Tue Jan 24 19:35:55 PST 2006


> > Ensel Sharon wrote:
> > > 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 ?
> >
> > % echo '9 8 11 14' | sort -nt ' ' | head -1
> > 8
>
>
> Yeah, but I am looking for "0" ... 8,9,11,14 are all in use ... but 0-7
> are not.  I want to:
>
> "starting with zero, find the lowest number that is NOT in this list"
>
> (where "this list" is the output of mdconfig -l, which shows which md
> devices are currently in use)

Running mdconfig -l I don't get any output, however this works, it'll
find the first unused number up to 25 in that list.

echo '8 9 11 14' | perl -ane'@h{@F}=(1)x at F;for(0..25){if(not defined
$h{$_}){print qq($_\n);exit}}'

If you can give me the exact output of mdconfig -l, I can modify this for you.
Luke


More information about the freebsd-questions mailing list