From 5fcad700087b26f533123eff017f1a8f99d21806 Mon Sep 17 00:00:00 2001 From: Edward Plainview Date: Tue, 8 Jan 2019 15:54:42 +0100 Subject: [PATCH] Fix spaces in directory names. Glob directories. --- plugins/disk/dirsizes | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/plugins/disk/dirsizes b/plugins/disk/dirsizes index 1d417847..0767243d 100755 --- a/plugins/disk/dirsizes +++ b/plugins/disk/dirsizes @@ -21,6 +21,8 @@ # You can test this plugin by calling it with params "test" and your watchdirs: # ./dirsizes test /dir1,/tmp/dir2 # +# The directories can contain wildcards that are automatically expanded. +# # ############################################################################## # @@ -45,6 +47,17 @@ else { @watchdirs = split( ",", $ENV{"watchdirs"} ); } +# Glob all of the watchdirs. +my @globbed_watchdirs; +foreach my $watchdir ( @watchdirs ) +{ + foreach my $expanded_dir ( glob( $watchdir ) ) + { + push @globbed_watchdirs, $expanded_dir; + } +} +@watchdirs = @globbed_watchdirs; + # Config or read request? if ( exists $ARGV[0] and $ARGV[0] eq "config" ) { @@ -88,9 +101,8 @@ sub getSize { my ($dir) = @_; # Get the size via `du` - my @dirsize = split( ' ', `du -cb $dir | grep "total" | tail -1 ` ); + my @dirsize = split( ' ', `du -cb "$dir" | grep "total" | tail -1 ` ); return @dirsize[0]; } exit 0; -