Patch for xymonclient-darwin.sh to fix numerous bugs
list Jason White
Greetings, The following patch fixes these long-standing issues with xymonclient-darwin.sh: * Disk usage test erroneously uses inode usage values as Darwin combines disk usage and inode usage into the same 'df' output by default. * Mountpoints with spaces in them were not reported. The former issues is fixed by passing the '-P' flag to 'df' to restore legacy mode reporting. The latter issue replaces spaces with underscores in the mountpoint. In addition to checking mount options for 'nobrowse', this patch also exclude readonly volumes which I find are mostly transient DMG files. Regards, -Jason -- Jason White user-bcd1a66a8ba8@xymon.invalid
Attachments (1)
list Jeremy Laidman
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. 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". Cheers Jeremy
▸
On 18 October 2015 at 23:17, Jason White <user-bcd1a66a8ba8@xymon.invalid> wrote:
Greetings, The following patch fixes these long-standing issues with xymonclient-darwin.sh: * Disk usage test erroneously uses inode usage values as Darwin combines disk usage and inode usage into the same 'df' output by default. * Mountpoints with spaces in them were not reported. The former issues is fixed by passing the '-P' flag to 'df' to restore legacy mode reporting. The latter issue replaces spaces with underscores in the mountpoint. In addition to checking mount options for 'nobrowse', this patch also exclude readonly volumes which I find are mostly transient DMG files. Regards, -Jason -- Jason White user-bcd1a66a8ba8@xymon.invalid
list Menelos
▸
On Oct 19, 2015, at 1:45 AM, Jeremy Laidman <user-71895fb2e44c@xymon.invalid> 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
user-bcd1a66a8ba8@xymon.invalid
list Japheth Cleaver
Thanks, Jason. Looks good! It's committed in https://sourceforge.net/p/xymon/code/7702/ and will be in the next release. Regards, -jc
▸
On Mon, October 19, 2015 9:48 am, Menelos wrote:On Oct 19, 2015, at 1:45 AM, Jeremy Laidman <user-71895fb2e44c@xymon.invalid> 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 user-bcd1a66a8ba8@xymon.invalid