Koozali.org: home of the SME Server

Directory Sort Challenge

Offline gbentley

  • ****
  • 482
  • +0/-0
  • Forum Lurker
    • Earth
Directory Sort Challenge
« 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 :)
"If you don't know what you want, you end up with a lot you don't."

Offline Daniel B.

  • *
  • 1,699
  • +0/-0
    • Firewall Services, la sécurité des réseaux
Re: Directory Sort Challenge
« Reply #1 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)
C'est la fin du monde !!! :lol:

Offline gbentley

  • ****
  • 482
  • +0/-0
  • Forum Lurker
    • Earth
Re: Directory Sort Challenge
« Reply #2 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?
« Last Edit: February 07, 2017, 10:18:54 AM by gbentley »
"If you don't know what you want, you end up with a lot you don't."

Offline Stefano

  • *
  • 10,836
  • +2/-0
Re: Directory Sort Challenge
« Reply #3 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

Offline gbentley

  • ****
  • 482
  • +0/-0
  • Forum Lurker
    • Earth
Re: Directory Sort Challenge
« Reply #4 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.
"If you don't know what you want, you end up with a lot you don't."

Offline Daniel B.

  • *
  • 1,699
  • +0/-0
    • Firewall Services, la sécurité des réseaux
Re: Directory Sort Challenge
« Reply #5 on: February 07, 2017, 10:35:30 AM »
This script requires perl-Quota. There's one RPM in fws repo
C'est la fin du monde !!! :lol:

Offline gbentley

  • ****
  • 482
  • +0/-0
  • Forum Lurker
    • Earth
Re: Directory Sort Challenge
« Reply #6 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...
« Last Edit: February 07, 2017, 10:54:04 AM by gbentley »
"If you don't know what you want, you end up with a lot you don't."

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: Directory Sort Challenge
« Reply #7 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 :-)