ZFS no longer mounted in alphanumerical order

Trond Endrestøl Trond.Endrestol at fagskolen.gjovik.no
Tue Mar 12 11:38:16 UTC 2019


On Tue, 12 Mar 2019 12:14+0100, Trond Endrestøl wrote:

> On Tue, 12 Mar 2019 11:37+0100, Jan Martin Mikkelsen wrote:
> 
> > > On 12 Mar 2019, at 10:37, Trond Endrestøl <Trond.Endrestol at fagskolen.gjovik.no> wrote:
> > > I concocted a shell script, it looks promising:
> > > 
> > > #!/bin/sh
> > > #-
> > > # Parallel mounting of ZFS filesystems leaves a chaotic listing of
> > > # mounted filesystems when viewed by df(1).
> > > # Separating the header from the remaining lines and sorting the
> > > # latter before recombining is a viable solution.
> > > #-
> > > 
> > > DF=/bin/df
> > > 
> > > ${DF} ${@} | grep    ^Filesystem
> > > ${DF} ${@} | grep -v ^Filesystem | sort -k 6
> > > 
> > > # new-df.sh
> > 
> > An alternative sort approach, which handles df arguments which change the number of columns, and only invokes df once:
> > 
> > ${DF} "$@" | awk '/^Filesystem/ { print; sort = "sort -k " NF } ! /^Filesystem/ { print | sort }’
> 
> Well, yes and no, mostly no.
> 
> Why are we feeding each line from df(1) separately to sort(1)?
> It defeats the entire purpose. No sorting takes place.
> 
> We might be better off accumulating the majority of the lines and 
> sorting them in an END block.

How about this?

/bin/df ${@} | /usr/bin/awk '/^Filesystem/ { print; sort = "/usr/bin/sort -sk " NF-1 } ! /^Filesystem/ { if (length(acc) > 0) acc = acc "\n" $0; else acc = $0; } END { print acc | sort }'

-- 
Trond.


More information about the freebsd-current mailing list