{"id":818,"date":"2015-01-06T00:37:29","date_gmt":"2015-01-06T05:37:29","guid":{"rendered":"http:\/\/xfloyd.net\/blog\/?p=818"},"modified":"2015-02-12T17:17:47","modified_gmt":"2015-02-12T22:17:47","slug":"qmail-mailbox-cleaner","status":"publish","type":"post","link":"https:\/\/xfloyd.net\/blog\/?p=818","title":{"rendered":"Qmail mailbox cleaner"},"content":{"rendered":"<p>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.<br \/>\nWorks ok PLESK systems on CentOS.<br \/>\n<!--more--><\/p>\n<pre>#!\/bin\/bash\r\n\r\n#Qmail Path\r\nPATH1=\"\/var\/qmail\/mailnames\/\"\r\nPATH2=\"Maildir\/cur\/\"\r\n\r\n\r\nfor folder1 in $PATH1*\/ ; do\r\n\t\r\n\tfor folder2 in $folder1*\/ ; do\r\n\r\n\t\tif [ -e \"$folder2$PATH2\" ]\r\n\t\tthen\r\n\t\t\tcur_size=$(du $folder2$PATH2 | cut -f1;)\r\n\t\t\tif [ $cur_size -gt 250000 ] \r\n\t\t\tthen\r\n\r\n\t\t\t\ti=\"0\"\r\n\t\t\t\twhile [ $i -lt 5000000 ]\r\n\t\t\t\t\tdo\r\n\r\n\t\t\t\t\tvar1=$(find $folder2$PATH2 -maxdepth 1 -type f -printf '%T+ %s %p\\n'| sort -n | head -1)\r\n\t\t\t\t\techo \"$var1 <- file to remove\";\r\n\t\t\t\t\tset $var1;\r\n\t\t\t\t\t#echo $3\r\n\t\t\t\t\t$(rm \"$3\")\r\n\t\t\t\t\t\r\n\t\t\t\t\ti=$((i+$2))\r\n\t\t\t\t\techo $i\r\n\t\t\t\tdone\r\n\t\t\tfi\r\n\t\tfi\r\n\tdone; \r\ndone;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/818"}],"collection":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=818"}],"version-history":[{"count":8,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/818\/revisions"}],"predecessor-version":[{"id":835,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/818\/revisions\/835"}],"wp:attachment":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=818"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=818"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}