Re: ZFS no longer mounted in alphanumerical order

From: Trond Endrestøl <Trond.Endrestol_at_fagskolen.gjovik.no>
Date: Tue, 12 Mar 2019 12:38:11 +0100 (CET)
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} ${_at_} | grep    ^Filesystem
> > > ${DF} ${_at_} | 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} "$_at_" | 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 ${_at_} | /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.
Received on Tue Mar 12 2019 - 10:38:15 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:41:20 UTC