The Blog

Qmail mailbox cleaner Posted on

This script go over all Qmail mailboxes and removes oldest emails from accounts that are over 250MB in size and removes 5MB worth of emails.
Works ok PLESK systems on CentOS.

#!/bin/bash

#Qmail Path
PATH1="/var/qmail/mailnames/"
PATH2="Maildir/cur/"


for folder1 in $PATH1*/ ; do
	
	for folder2 in $folder1*/ ; do

		if [ -e "$folder2$PATH2" ]
		then
			cur_size=$(du $folder2$PATH2 | cut -f1;)
			if [ $cur_size -gt 250000 ] 
			then

				i="0"
				while [ $i -lt 5000000 ]
					do

					var1=$(find $folder2$PATH2 -maxdepth 1 -type f -printf '%T+ %s %p\n'| sort -n | head -1)
					echo "$var1 <- file to remove";
					set $var1;
					#echo $3
					$(rm "$3")
					
					i=$((i+$2))
					echo $i
				done
			fi
		fi
	done; 
done;
This entry was posted in PLESK. Bookmark the permalink.

Please Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *



CAPTCHA
Change the CAPTCHA codeSpeak the CAPTCHA code