Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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?
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.
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.