The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 05-14-2008
phpfreak phpfreak is offline
Registered User
 

Join Date: Feb 2008
Posts: 9
Script to count files and get the disk usgae on individual mail folders

I have several mail accounts using dovecot maildr format for which I'd like to create a script so that when I run it, for each user it prints not only the name of the user but all of the folders contained and outputs each of the names of the folders created by the user (including the default cur, new, tmp dirs) with a wc on the number of files in each and du consumed by that folder.

Here's a general run down of how the dir structure is..
$ pwd
/stats/mail
$ ls -lAh
total 3
drwx------ 5 473177 client 512B May 14 07:55 .jklein
drwx------ 5 473177 client 512B Feb 22 19:41 .pow103
drwx------ 5 473177 client 512B Aug 4 2007 .test
$ cd .test
$ ls -lah
total 6
drwx------ 5 473177 client 512B Aug 4 2007 .
drwx------ 5 473177 client 512B Aug 4 2007 ..
drwx------ 2 473177 client 512B Aug 4 2007 cur
-rw------- 1 473177 client 37B Aug 4 2007 dovecot-uidlist
drwx------ 2 473177 client 512B Aug 4 2007 new
drwx------ 2 473177 client 512B Aug 4 2007 tmp
$ cd cur
$ ls -lah
total 5
drwx------ 2 473177 client 512B Aug 4 2007 .
drwx------ 5 473177 client 512B Aug 4 2007 ..
-rw------- 1 473177 client 1K Feb 18 2005 1108726486.Q00001.v
$ du -khd 1
2.0K .

I'd like it to output the information in a user friendly format so a script that just captures these variables is enough for me:
$UsrA
$UsrAFldrAmsgnumb
$UsrAFldrAsize
$UsrAFldrBmsgnumb
$UsrAFldrBsize
$UsrB
$UsrBFldrAmsgnumb
$UsrBFldrAsize
$UsrBFldrBmsgnumb
$UsrBFldrBsize
$UsrC
$UsrCFldrAmsgnumb
$UsrCFldrAsize
$UsrCFldrBmsgnumb
$UsrCFldrBsize

And so on and so forth with the amt of users and sub folders being dynamic. Thanks in advance for your help.
Reply With Quote
Forum Sponsor