On Oct 19, 2015, at 1:45 AM, Jeremy Laidman <jlaidman at rebel-it.com.au> wrote:
Jason
Nice work.
A suggestion, to avoid setting oIFS and then having to clean up again later:
FILESYSTEMS=`mount | egrep -v '[\( ](nobrowse|read-only)[ ,\)]' | sed 's/^.* on \(.*\) (.*)$/\1/'` echo "[df]" (IFS=$'\n' set $FILESYSTEMS df -PH $1; shift while test $# -gt 0 do df -PH $1 | tail -1 | sed 's/\([^ ]\) \([^ ]\)/\1_\2/g' shift done) | column -t -s " " | sed -e 's!Mounted *on!Mounted on!'
By moving "IFS=..." and "set $FILESYSTEMS" into the parens, the scope of the variable change is kept within the parens, thus auto-cleanup.
Great idea. I also had to change the inode test a bit since originally I didn't restore IFS until after both df and inode tests ran.
A second suggestion is to replace the egrep+sed pipeline with a single sed command, such as:
FILESYSTEMS=`mount | sed '/[\( ](nobrowse|read-only)[ ,\)]/d;s/^.* on \(.*\) (.*$/\1/'`
This saves an extra process fork/exec. The "/<regexp>/d" operation for sed will delete matching lines, emulating "egrep -v".
I'm all for saving forks/execs. To make your example work, though, I had to call sed with '-E' to enable extended regular expressions and change which parens I escaped in the substitution expression. This updated patch also skips AFS mounts. I appreciate your feedback! -Jason --- xymonclient-darwin.sh.orig 2015-10-17 18:19:14.000000000 -0500 +++ xymonclient-darwin.sh 2015-10-19 11:41:39.000000000 -0500 @@ -26,22 +26,24 @@ echo "[who]" who -FILESYSTEMS=`mount | grep -v nobrowse | awk '{print $3}'` +FILESYSTEMS=`mount | sed -E '/[\( ](nobrowse|afs|read-only)[ ,\)]/d;s/^.* on (.*) \(.*$/\1/'` echo "[df]" -set $FILESYSTEMS -(df -H $1; shift +(IFS=$'\n' + set $FILESYSTEMS + df -PH $1; shift while test $# -gt 0 do - df -H $1 | tail -1 + df -PH $1 | tail -1 | sed 's/\([^ ]\) \([^ ]\)/\1_\2/g' shift done) | column -t -s " " | sed -e 's!Mounted *on!Mounted on!' echo "[inode]" -set $FILESYSTEMS -(df -i $1; shift +(IFS=$'\n' + set $FILESYSTEMS + df -i $1; shift while test $# -gt 0 do - df -H $1 | tail -1 + df -H $1 | tail -1 | sed 's/\([^0123456789% ]\) \([^ ]\)/\1_\2/g' shift done) | awk ' NR<2{printf "%-20s %10s %10s %10s %10s %s\n", $1, "itotal", $6, $7, $8, $9} -- Jason White jdwhite at menelos.com