Menu

#120 zz-disk_space regression/not working in logwatch 7.7 & 7.12

v7.12
closed
nobody
None
5
2025-07-22
2025-02-11
No

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.

Related

Bugs: #120

Discussion

  • Gerald Rosenberg

    Commenting out lines 63-66 allows zz-disk_space to produce correct output.

     
  • Bjorn

    Bjorn - 2025-02-16

    Let me know if the attached patch fixes it.

     
  • Gerald Rosenberg

    Unfortunately not. Correct info is printed for the home directories (a set of subdirectories) , but nothing is printed for the mail directory (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 home and mail directories. The command du -sh * can then summarize whatever it finds in those directories.

     
  • Bjorn

    Bjorn - 2025-03-02

    I think /var/spool/mail allows 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_sizes variable.

    The script essentially executes du commands, with different options depending on the actual OS it is running on.

     
  • iridos

    iridos - 2025-03-10

    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:

    sub DirectorySizes
    {
        my $Dir = $_[0];
        DirUsage($Dir.'/*');
    }
    

    or do something like

    sub DirUsage {
        my $Dir = $_[0];
        while ($Dir = glob($Dir)){
            if ( !-d $Dir ) {
               print "Directory $Dir not found\n";
               return
            };
            # truncated function at this point
    

    Cheers,
    K.

     

    Last edit: iridos 2025-03-11
  • Bjorn

    Bjorn - 2025-03-23

    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).

     
  • iridos

    iridos - 2025-03-24

    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:

    sub DirUsage {
        my $Dir = $_[0];
            if ( !-d $Dir ) {
               print STDERR "Directory $Dir not found\n";
               return
            };
    

    DirUsage is being called with DirUsage($Dir.'/*'); and configured for the $Dir at this point of calling is "/home"
    so in the sub DirUsage my $Dir = "/home/*";

    $ perl -e '$Dir = "/home/*";   if ( !-d $Dir ) { print("your code does not work\n");}' 
    your code does not work
    

    What would work:

    sub DirUsage {
        my $Dir = $_[0];
        while ($Dir = glob($Dir)){
            if ( !-d $Dir ) {
               print "Directory $Dir not found\n";
               return
            };
    .
    .
    .
    .
    
     

    Last edit: iridos 2025-03-24
    • Mike Tremaine

      Mike Tremaine - 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 ( !-d $Dir ) {
      • print STDERR "Directory $Dir not found\n";
      • return
      • };
      • if ( !-d $Dir ) {
      • print STDERR "Directory $Dir not found\n";
      • return
      • };
      • $Dir = $Dir . "/"; # Add / to the end of the directory name for globbing -mgt
        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];
      • DirUsage($Dir.'/*');
      • DirUsage($Dir); #Do not add a glob here -mgt
        }

      Committed …

      On Mar 24, 2025, at 2:36 AM, iridos iridos2@users.sourceforge.net wrote:

      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:

      sub DirUsage {
      my $Dir = $_[0];
      if ( !-d $Dir ) {
      print STDERR "Directory $Dir not found\n";
      return
      };
      DirUsage is being called with DirUsage($Dir.'/'); and configured for the $Dir at this point of calling is "/home"
      so in the sub DirUsage my $Dir = "/home/
      ";

      $ perl -e '$Dir = "/home/*"; if ( !-d $Dir ) { print("your code does not work\n");}'
      your code does not work
      [bugs:#120] https://sourceforge.net/p/logwatch/bugs/120/ zz-disk_space regression/not working in logwatch 7.7 & 7.12

      Status: open
      Group: v7.12
      Created: Tue Feb 11, 2025 10:15 PM UTC by Gerald Rosenberg
      Last Updated: Sun Mar 23, 2025 12:34 AM UTC
      Owner: nobody

      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.

      Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/logwatch/bugs/120/

      To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

       

      Related

      Bugs: #120

  • Bjorn

    Bjorn - 2025-07-22
    • status: open --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB