LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-04-2008, 11:06 AM   #1
carlosinfl
Senior Member
 
Registered: May 2004
Location: Orlando, FL
Distribution: Arch
Posts: 2,905

Rep: Reputation: 77
How To Determine Mailbox Size (Postfix)


I am using Postfix as an email server. Right now there is no mailbox quota limit size but I think 2048M is more than enough for the average user on my email server. Right now everyone has their email in their own home directory folder called Maildir (maildir style) and I was wondering how I can find each users mailbox size besides having to do "du -h /home/user/Maildir" command individually for all 300 users.

Does anyone have any suggestions as I have no experience with bash / shell scripts and would not know where to start.

I assume many of you guys manage / admin a large robust Postfix email server and would know some tips and or tricks to help me filter and get the data I am looking for.
 
Old 06-04-2008, 11:42 AM   #2
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Something like this might work for you to get listing:

Code:
for USER in `ls /home`
   do
     du -sh /home/$USER/Maildir
done
Notice the -sh instead of just -h, this will not give a total size of each file within the Maildir, instead giving total usage for the whole Maildir, cleaner output to read.

Last edited by trickykid; 06-04-2008 at 11:44 AM.
 
Old 06-04-2008, 11:48 AM   #3
carlosinfl
Senior Member
 
Registered: May 2004
Location: Orlando, FL
Distribution: Arch
Posts: 2,905

Original Poster
Rep: Reputation: 77
Are you saying I should run the command:

Code:
du -sh /home/$USER/Maildir
or was that a suggested shell script?
 
Old 06-04-2008, 11:52 AM   #4
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Quote:
Originally Posted by Carlwill View Post
Are you saying I should run the command:

Code:
du -sh /home/$USER/Maildir
or was that a suggested shell script?
You have to run the whole script, not just the du command portion of it.

Basically let's break it down:

Code:
for USER in `ls /home`
This assigns the variable to each user from the ls command to get the list of everyone's home directory that might have a Maildir within it.

Code:
do
This simply tells us what were going to do with the variables, basically the next step.

Code:
du -sh /home/$USER/Maildir
The command were running against each variable assigned from the list of users in the /home directory.

Code:
done
We're telling the script we're all done now.

Make sense?
 
Old 06-04-2008, 12:14 PM   #5
carlosinfl
Senior Member
 
Registered: May 2004
Location: Orlando, FL
Distribution: Arch
Posts: 2,905

Original Poster
Rep: Reputation: 77
Thanks for the break down. That script worked perfect. If I wanted to filter the results for anything larger than 1.0G, how would that sit in the script?
 
Old 06-04-2008, 12:33 PM   #6
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
You could run the whole command like this most likely:

Code:
for USER in `ls /home`; do du -sh /home/$USER/Maildir; done | awk '$1 > 100000000000 {print $1, $2}'
I changed it to bytes instead of human readable as it's easier to use bytes with awk instead, but that should print off all the users with a Maildir above 1GB in size.
 
Old 06-04-2008, 06:30 PM   #7
carlosinfl
Senior Member
 
Registered: May 2004
Location: Orlando, FL
Distribution: Arch
Posts: 2,905

Original Poster
Rep: Reputation: 77
Thanks again Trickykid!

From that I created a shell script which I ran as so:

Code:
[cwilliams@mail ~]$ sudo ./disk_space 1000000
*****************************************************************
1.9G dsanza
1.1G hkazzoun
As you can see I run the script with the size I am looking for and it displays the results human readable for me.

Here is the script:

Code:
if [ "$1" = "" ]; then
     echo "*****************************************************************"
     echo
     echo "Enter quota amount to be compared to the mailbox size - 600000 is 600M ...."
     echo
     echo "*****************************************************************"
     else
     echo "*****************************************************************"
          for USER in `ls /home`
            do
            if [ -d /home/$USER/Maildir ]; then
               DISKSPACE=`du -s /home/$USER/Maildir|awk '{print $1}'`
                  if [ $DISKSPACE -gt $1 ]; then
                  DISKSPACE=`du -sh /home/$USER/Maildir|awk '{print $1}'`
                  echo "$DISKSPACE $USER"
                  fi
            fi
          done
     echo "*****************************************************************"
fi
 
Old 06-05-2008, 07:38 AM   #8
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Cool. Yeah, I prefer human readable most of the time but when I write scripts that check sizes, I always resort to bytes. But glad my examples helped you come up with a script to suit your own needs.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Postfix Mailbox Size carlosinfl Linux - Server 3 08-17-2007 02:29 PM
postfix mailbox location yogaboy Linux - Software 5 12-19-2006 06:37 PM
virtual mailbox with postfix shafey Linux - Networking 0 07-19-2006 02:16 AM
postfix virtual mailbox namit Debian 1 12-16-2005 02:06 AM
Managing mailbox size george_milescu Linux - Software 0 12-01-2005 05:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 08:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration