bithead42 has asked for the wisdom of the Perl Monks concerning the following question:

I am so new to perl that "noob" is probably too generous a description. I am a Linux admin and have recently upgraded a server from Debian Lenny to Debian Jessie. The previous admin who built the Lenny server left behind some perl scripts, one of which I am unable to get running on new server. It says:

Can't locate Filesys/DiskUsage.pm in @INC (you may need to install the Filesys::DiskUsage module)

So I did some digging and found that I should install cpanminus and use it to install the the missing module. When I do so while logged in as root, it says:

cpan Filesys::DiskUsage Reading '/root/.cpan/Metadata' Database was generated on Tue, 07 Feb 2017 01:53:38 GMT Running install for module 'Filesys::DiskUsage' Checksum for /root/.cpan/sources/authors/id/M/MA/MANWAR/Filesys-DiskUs +age-0.10.tar.gz ok 'YAML' not installed, will not store persistent state Configuring M/MA/MANWAR/Filesys-DiskUsage-0.10.tar.gz with Makefile.PL Checking if your kit is complete... Looks good Generating a Unix-style Makefile Writing Makefile for Filesys::DiskUsage Writing MYMETA.yml and MYMETA.json MANWAR/Filesys-DiskUsage-0.10.tar.gz /usr/bin/perl Makefile.PL INSTALLDIRS=site -- OK Running make for M/MA/MANWAR/Filesys-DiskUsage-0.10.tar.gz cp lib/Filesys/DiskUsage.pm blib/lib/Filesys/DiskUsage.pm cp fdu blib/script/fdu /usr/bin/perl -MExtUtils::MY -e 'MY->fixin(shift)' -- blib/script/fdu Manifying blib/man1/fdu.1p Manifying blib/man3/Filesys::DiskUsage.3pm MANWAR/Filesys-DiskUsage-0.10.tar.gz /usr/bin/make -- OK Running make test PERL_DL_NONLAZY=1 PERL_USE_UNSAFE_INC=1 /usr/bin/perl "-MExtUtils::Com +mand::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; tes +t_harness(0, 'blib/lib', 'blib/arch')" t/*.t t/00.load.t .......................... 1/1 # Testing Filesys::DiskUsag +e 0.10 t/00.load.t .......................... ok t/01.basic.t ......................... ok t/02.warnings.t ...................... 1/2 # Failed test 'warning for permission denied' # at t/02.warnings.t line 40. # didn't find a warning # expected to find warning: (?^:^could not open /tmp/b1jhnkInea/sub \( +.+\)$) # Failed test 'size of one file' # at t/02.warnings.t line 42. # got: '10' # expected: '5' # We run this again to see what are the various error messages in diff +erent locales. There will be a warning next line: # $ENV{LANG}: en_US.UTF-8 # Looks like you failed 2 tests of 2. t/02.warnings.t ...................... Dubious, test returned 2 (wstat + 512, 0x200) Failed 2/2 subtests t/03.rmtree.t ........................ ok t/71-version_numbers_are_the_same.t .. ok t/pod-coverage.t ..................... skipped: Test::Pod::Coverage 1. +04 required for testing POD coverage t/pod.t .............................. skipped: Test::Pod 1.14 require +d for testing POD Test Summary Report ------------------- t/02.warnings.t (Wstat: 512 Tests: 2 Failed: 2) Failed tests: 1-2 Non-zero exit status: 2 Files=7, Tests=26, 0 wallclock secs ( 0.02 usr 0.00 sys + 0.10 cusr + 0.00 csys = 0.12 CPU) Result: FAIL Failed 1/7 test programs. 2/26 subtests failed. Makefile:851: recipe for target 'test_dynamic' failed make: *** [test_dynamic] Error 255 MANWAR/Filesys-DiskUsage-0.10.tar.gz /usr/bin/make test -- NOT OK //hint// to see the cpan-testers results for installing this module, t +ry: reports MANWAR/Filesys-DiskUsage-0.10.tar.gz

And I have no idea what to do with that information. I've included the script here in case it might be helpful:

#!/usr/bin/perl #PURPOSE - get each users inbox & imap storage sizes use strict; use warnings; use FileHandle; print "\n"x2; inboxsize(); print "\n"x2; mailboxsize(); my %hash; my $version = '.93'; my %folderhash; sub inboxsize{ my $dir = '/var/mail'; my $alert_size = '199.99'; my $alert_mark = ' <-----'; opendir my $dh, $dir or do { warn "Cannot open '$dir' $!"; }; my ($name, $size) = ( '', '' ); my $rounded; while ( my $file = readdir $dh ) { $size = ( stat "$dir/$file" )[ 7 ] or do { # warn "Cannot stat '$dir/$file' $!"; # last; }; ($name, $size) = ($file, ($size / (1024*1024))); $rounded = sprintf('%.2f', $size); #if ($rounded >= $alert_size){$rounded=$rounded.$alert_mark}; if ($name =~ /^\./){next}; $hash{"$name"}="$rounded"; }; print "Mail Inbox sizes > $alert_size MB as of ". scalar (localtime) . +"\n\n\n"; # sort by value, rather than key foreach (sort {$hash{$a} <=> $hash{$b}} keys %hash) { if ($hash{$_} >= $alert_size){write}; } print '-'x41,"\n\n"; } sub mailboxsize{ use Filesys::DiskUsage qw/du/; #my $dir = '/Big-Drive/Fedora/'; my $dir = '/home/'; my $mdir = '/mail/'; my $alert_size = '499.99'; # get the usernames and put in @array opendir(DIR,"$dir") or die "Couldn't open $dir directory!\n"; push (my @array, grep {!/^\./} readdir (DIR)); close (DIR); foreach (@array){ my $name = "$dir$_$mdir"; if (-d "$name"){ my $tot=du ({ 'sector-size' => 1024 }, qq'$name'); my $totMB = sprintf('%.2f', ($tot / (1024*1024))); $hash{"$_"}="$totMB"; } } print "Mail directory sizes > $alert_size MB as of ". scalar (localtim +e) ."\n\n\n"; # sort by value, rather than key foreach (sort {$hash{$a} <=> $hash{$b}} keys %hash) { if ($hash{$_} >= $alert_size){ STDOUT->format_name("STDOUT"); write; # mail directory total size # start getting folder sizes for each largemaildir user my $name = "$dir$_$mdir"; # /home/user/mail/ opendir(DIR,"$name") or die "Couldn't open $name directory!\n"; push (my @array, grep {!/^\./} readdir (DIR)); # get the folder na +mes close (DIR); undef %folderhash; foreach (@array){ # get folder sizes and put in %folderhash # if (-f "$name$_"){ my $tot=du ({ 'sector-size' => 1024 }, qq'$name$_'); my $totMB = sprintf('%.2f', ($tot / (1024*1024))); $folderhash{"$_"}="$totMB"; # }; }; # sort by value, rather than key STDOUT->format_name("MIDDLE"); foreach (sort {$folderhash{$a} <=> $folderhash{$b}} keys %folder +hash) {write} # mail folder sizes }; } print '-'x41,"\n\n"; } print "Printed by $0 version $version at ". scalar (localtime) ."\n"; format STDOUT = @<<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>>>>>>> $_, $hash{$_} . format MIDDLE = @<<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>>>>>>> $_, $folderhash{$_} .

Please be gentle and generous with your step by step advice on how I should proceed.

Replies are listed 'Best First'.
Re: Module Installation Errors
by Anonymous Monk on Feb 07, 2017 at 04:07 UTC

    It appears that the test script is trying to cause a warning by making a file unreadable, then reading it. This fails as root, because root can read anything. Try running the test as a normal user, and see if it passes. If it does, you can go ahead and force install as root.

    Many people prefer to use a build system (like perlbrew) that installs modules as a normal user so that they don't need to run cpan as root.

      Thanks for the explanation. Running the cpan installation as a normal user and using the 'sudo' method did the trick - the script runs now! As for perlbrew, this looks like it installs and upgrades perl itself, not perl modules - is that correct? For the installation of perl itself, I used the Debian package appropriate to my installation.

      Thanks again!
        Yes, it does both things (installing perl and installing modules) without needing root. Glad you got it to work!
Re: Module Installation Errors
by dave_the_m (Monsignor) on Feb 07, 2017 at 09:10 UTC
    If you are using the system perl, then there will probably already be a packaged version of the module you want. I'm not terribly familiar with Debian (more of a Fedora man myself) but I assume you do something with apt-get.

    Dave.

      Thanks for the reply, Dave. As Hauke D indicated there is no Debian package for the module in question. Anonymous nailed it though, noting that running cpan as root is not the preferred method, and that was indeed the cause of the errors I received.