Koozali.org: home of the SME Server

Contribs.org Forums => General Discussion => Topic started by: gbentley on February 07, 2017, 09:39:12 AM

Title: Directory Sort Challenge
Post by: gbentley on February 07, 2017, 09:39:12 AM
Hi All,

I am trying to sort /home/e-smith/files/users into something sensible so that I can send out an automated monthly summary of size.

Here's my feeble effort so far...

# du -h --max-depth=1 | sort -n -r > totals.txt

The problem with this is that the outputted list is a little jumbled...

447M
8.0K
7.1G

So now I need to get all those user with 'G' at the top of the list, then 'M' and if I could remove the du total entirely that would be good.

Any tips?

Thanks :)
Title: Re: Directory Sort Challenge
Post by: Daniel B. on February 07, 2017, 10:10:56 AM
You need to remove the -h for sort -n to be effective.

Here's a small script I use for this:

https://wikit.firewall-services.com/doku.php/tuto/ipasserelle/divers/stat_espace_par_utilisateur

use it as
Code: [Select]
perl quota.pl > totals.csv
You can then open it with Excel or Calc if you want to format it further. It'll print for each users the space used by their mailbox, their home dir, and the total space (email + home + files created in ibays/shared folders)
Title: Re: Directory Sort Challenge
Post by: gbentley on February 07, 2017, 10:15:29 AM
Thanks for this. I'm only interested in the size of their email directories though. Will see if I can mod this to do that :)

I also need to run this monthly. Is it equally possible to execute a perl job from crontab as you can with a shell script?
Title: Re: Directory Sort Challenge
Post by: Stefano on February 07, 2017, 10:24:02 AM
usually I use
Code: [Select]
du -s -m * | sort -nr | head
to find the biggest/heaviest dirs
Title: Re: Directory Sort Challenge
Post by: gbentley on February 07, 2017, 10:34:25 AM
use it as
Code: [Select]
perl quota.pl > totals.csv

Code: [Select]
# perl quota.pl
Can't locate quota.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at quota.pl line 3.
BEGIN failed--compilation aborted at quota.pl line 3.
Title: Re: Directory Sort Challenge
Post by: Daniel B. on February 07, 2017, 10:35:30 AM
This script requires perl-Quota. There's one RPM in fws repo
Title: Re: Directory Sort Challenge
Post by: gbentley on February 07, 2017, 10:40:19 AM
This script requires perl-Quota. There's one RPM in fws repo

Thanks :)

Was kinda hoping to do this with stock tools etc and have to have units that users understand ie GB, MB etc

Maybe grepping G and M is separate passes...
Title: Re: Directory Sort Challenge
Post by: CharlieBrady on February 08, 2017, 04:11:13 PM
Was kinda hoping to do this with stock tools etc and have to have units that users understand ie GB, MB etc

Post-process the numbers after the sort has been done.

Or teach your users some basic arithmetic :-)