Current time: 12-22-2024, 04:53 PM Hello There, Guest! (LoginRegister)


Post Reply 
[Shell] Größe der Postfächer ermitteln
Author Message
Knut Offline
Member
***

Posts: 736
Joined: Nov 2006
Reputation: 10
Post: #1
[Shell] Größe der Postfächer ermitteln
Neben der Größe meiner gehosteten Sites interessiert mich auch monatlich die Postfachgröße. Dafür habe ich folgendes Shellscript:

Code:
pico /root/bin/mailfoldersize

Code:
#!/bin/bash

FOLDER="/var/mail/virtual/"

for domain in $(ls $FOLDER); do
        if [ `ls $FOLDER$domain -1a|wc -l` -gt 2 ]; then
                echo "Domain: $domain";
                echo "==================================";
                ## old version ## du -s $FOLDER$domain/*|sed "s#$FOLDER$domain/##g"|sort -gr;
                ## by tomhb
                du --max-depth 1 $FOLDER |sed "s#$FOLDER##g"| sort -gr | \
                awk '{ $1=$1/1024; printf "%.2f MB: \t%s\n",$1,$2 }'
                echo "";
                echo "";
        fi
done

echo "Alle Domains:"
echo "============="
du -s $FOLDER*/*|sed "s#$FOLDER##g"|sort -gr;
echo ""
echo ""

Ausführbar machen:
Code:
chmod +x /root/bin/mailfoldersize

und für die monatliche Zustellung die Crontab bearbeiten:
Code:
crontab -e

Code:
0       0       1 * * /root/bin/mailfoldersize | mail -s "[SERVERNAME] Postfach-Stats" "mailadresse@domain.tld" >/dev/null 2>&1
<- alles in einer Zeile !

Knut
(This post was last modified: 02-07-2011 04:29 PM by Knut.)
04-23-2009 04:38 AM
Find all posts by this user Quote this message in a reply
DiXeoN Offline
Member
***

Posts: 284
Joined: Feb 2008
Reputation: 2
Post: #2
RE: [Shell] Größe der Postfächer ermitteln
English translation:

Besides the size of my hosted sites, I'm also interested in the monthly mailbox size. I have the following shell script:

Code:
pico /root/bin/mailfoldersize
Code:
#!/bin/bash

FOLDER="/var/mail/virtual/"

for domain in $(ls $FOLDER); do
        if [ `ls $FOLDER$domain -1a|wc -l` -gt 2 ]; then
                echo "Domain: $domain";
                echo "==================================";
                du -s $FOLDER$domain/*|sed "s#$FOLDER$domain/##g"|sort -gr;
                echo "";
                echo "";
        fi
done

echo "All Domains:"
echo "============="
du -s $FOLDER*/*|sed "s#$FOLDER##g"|sort -gr;
echo ""
echo ""
Make it executable:
Code:
chmod +x /root/bin/mailfoldersize

For the monthly crontab:
Code:
crontab -e
Code:
0       0       1 * * /root/bin/mailfoldersize | mail -s "[SERVERNAME] Mailbox Stats" "your@mailadress.here" >/dev/null 2>&1
<- All in a single row!
04-23-2009 04:45 AM
Find all posts by this user Quote this message in a reply
TheCry Away
Member
***

Posts: 851
Joined: Oct 2008
Reputation: 21
Post: #3
RE: [Shell] Größe der Postfächer ermitteln
Hallo Knut,
Nutze doch zusätzlich noch die Option -h bei "du"
Quote:-h, --human-readable
print sizes in human readable format (e.g., 1K 234M 2G)

Sieht dementsprechend besser aus..
Ansonsten ist das und das andere Skript echt gut!

Gruß
Sascha

Edit:
english translation.
if you use "du -s -h" it will show you a better output of the dirsize.
(This post was last modified: 04-23-2009 06:09 AM by TheCry.)
04-23-2009 05:59 AM
Find all posts by this user Quote this message in a reply
joximu Offline
helper
*****
Moderators

Posts: 7,024
Joined: Jan 2007
Reputation: 92
Post: #4
RE: [Shell] Größe der Postfächer ermitteln
in short: "du -hs"

but the problem is the sorting afterwards...

/J
(This post was last modified: 04-23-2009 06:52 AM by joximu.)
04-23-2009 06:52 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Knut Offline
Member
***

Posts: 736
Joined: Nov 2006
Reputation: 10
Post: #5
RE: [Shell] Größe der Postfächer ermitteln
Der Nachteil ist dabei die anschließende Sortierung ! 120K kommt dann vor 33M als Beispiel.

en: The disadvantage is the subsequent sorting! 120K is more then 33M. SadShy

@ joximu : ups your are faster
(This post was last modified: 04-23-2009 03:09 PM by Knut.)
04-23-2009 03:08 PM
Find all posts by this user Quote this message in a reply
enrico73 Offline
Junior Member
*
Beta Team

Posts: 18
Joined: Mar 2010
Reputation: 0
Post: #6
RE: [Shell] Größe der Postfächer ermitteln
Bekommen leider nur eine leere Email. Hab grad das Script installiert und es kam auch eine Mail vom Cron. Kann mir einer sagen warum die mail leer ist?

Muss das Script in /root/bin sein oder geht es auch in root?
Gruß Rico

PS: erledigt!!!
(This post was last modified: 04-07-2010 07:37 AM by enrico73.)
03-24-2010 08:55 AM
Find all posts by this user Quote this message in a reply
gOOvER Offline
Banned

Posts: 3,561
Joined: Jul 2007
Post: #7
RE: [Shell] Größe der Postfächer ermitteln
Please ONLY english here Wink
03-24-2010 09:19 AM
Visit this user's website Find all posts by this user Quote this message in a reply
grisu Offline
Junior Member
*

Posts: 64
Joined: Jun 2009
Reputation: 0
Post: #8
RE: [Shell] Größe der Postfächer ermitteln
(04-23-2009 03:08 PM)Knut Wrote:  en: The disadvantage is the subsequent sorting! 120K is more then 33M. SadShy

Thank you Knut for this Script Smile
Based upon it I've got a tiny modification using awk instead of sed. Now it supports human readability (in megabytes) AND sorting which works for me.

Maybe some guys uf you may find this helpful...

Code:
#!/bin/bash

FOLDER="/var/mail/virtual/"

for domain in $(ls $FOLDER); do
        if [ `ls $FOLDER$domain -1a|wc -l` -gt 2 ]; then
                echo "Domain: $domain";
                echo "==================================";
                du -s $FOLDER$domain/*|sort -gr| awk '{printf("%.3f MB\t%-10s\n", ($1 / 1024), $2)}';
                echo "";
                echo "";
        fi
done

echo "Alle Domains:"
echo "============="
du -s $FOLDER*/*|sort -gr | awk '{printf("%.3f MB\t%-10s\n", ($1 / 1024), $2)}';
echo ""
echo ""

greetings and a nice Weekend
(This post was last modified: 08-07-2010 01:20 AM by grisu.)
08-07-2010 01:18 AM
Find all posts by this user Quote this message in a reply
mr.x Offline
Development Team
*****
Dev Team

Posts: 232
Joined: Nov 2006
Reputation: 3
Post: #9
RE: [Shell] Größe der Postfächer ermitteln
Hi grisu,

(08-07-2010 01:18 AM)grisu Wrote:  Maybe some guys uf you may find this helpful...

Thanks for your modification !

/Mr.X
08-29-2010 08:53 PM
Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 2 Guest(s)