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.
Free Guide: Linux from Scratch
Linux from Scratch describes the process of creating your own Linux system from scratch from an already installed Linux distribution, using nothing but the source code of software that you need.
This 318 page eBook provides readers with the background and instruction to design and build custom Linux systems. The resulting system will be compiled completely from the source code, and the user will be able to specify where, why, and how programs are installed. This eBook allows readers to fully customize Linux systems to their own needs and allows users more control over their system.
Click Here to receive the Linux from Scratch Guide absolutely free.
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.