Ubuntu 24.10
logwatch 7.7
Logwatch is failing to report home and maildir sizes.
Created and modified /etc/logwatch/conf/services/zz-disk_space.conf:
$show_home_dir_sizes = 1
$home_dir = "/home"
$show_mail_dir_sizes = 1
$mail_dir = "/var/spool/mail"
Logwatch reports:
...
------------- Home Directory Sizes ---------------
Size Location
Directory /home/* not found
------------- Home Directory Sizes ---------------
------------- Mail Directory Sizes ---------------
Size Location
Directory /var/spool/mail/* not found
------------- Mail Directory Sizes ---------------
---------------------- Disk Space End -------------------------
The v7.7 script /usr/share/logwatch/scripts/services/zz-disk_space appears to have an error at line 61-65 where the function parameter is -d tested. The function call at line 88 appends /* to the directory name so the directory test at line 62 is bound to fail.
The v7.12 script appears to be identical to the v7.7 script.
The v7.5.1 script is different: the DirUsage function does not perform a directory test.
Commenting out lines 63-66 allows
zz-disk_spaceto produce correct output.Let me know if the attached patch fixes it.
Unfortunately not. Correct info is printed for the
homedirectories (a set of subdirectories) , but nothing is printed for themaildirectory (a set of files).Not sure that I understand the purpose of testing for subdirectory existence. The directory test should, I think, be against just the
homeandmaildirectories. The commanddu -sh *can then summarize whatever it finds in those directories.I think
/var/spool/mailallows mail in Maildir format, which would create a subdirectory for each user in the mail spool directory. But if there aren't any subdirectories (as in a traditional mbox format, with just one file per user), then the best approach is to not enable the$show_mail_dir_sizesvariable.The script essentially executes
ducommands, with different options depending on the actual OS it is running on.The mistake is, that you are adding * for globbing, but then treating e.g.
/home/*itself as a direcotry name without using globbing. But the directory/home/*doesn't exist.You cannot do something lie
opendir DIR, "$Dir", because/home/*itself is not a directory.You either have to not add the
*here:or do something like
Cheers,
K.
Last edit: iridos 2025-03-11
I think your comment might apply to the repository code, before the proposed patch of Feb. 16th. The patch removes the
/*usage, and obtains the subdirectories through readdir (similar to your usage of glob).My comment applies exactly to from the current git, and the code I pasted above is still in
https://sourceforge.net/p/logwatch/git/ci/master/tree/scripts/services/zz-disk_space
(which you could have checked?)
Here it is again:
DirUsage is being called with
DirUsage($Dir.'/*');and configured for the$Dirat this point of calling is"/home"so in the sub DirUsage
my $Dir = "/home/*";What would work:
Last edit: iridos 2025-03-24
Fair enough. Let’s fix but moving the append /*
perl -e '$Dir = "/home"; if ( !-d $Dir ) { print("your code does not work\n");}; $Dir = $Dir . "/*"; print("$Dir Dir reset");' <— You test modified
Patch
sub DirUsage {
my $Dir = $_[0];
if ($OSname eq "Linux") {
system("du -s --block-size=1048576 -h $Dir | sort -n -r -k 1");
} elsif ($OSname eq "Darwin") {
@@ -85,7 +86,7 @@ sub DirUsage {
sub DirectorySizes
{
my $Dir = $_[0];
}
Committed …
Related
Bugs:
#120