I look over the forum and I do search but didnt find what I was looking for. So I would like to do automatic monthly prune of old emails of my customers. For example. I would like to automaticaly delete mails that are older than 6 months and which are in junk, trash and inbox folders, not deleting mails in other folders. Is that possible and how. I am new to linux so I would need detailed how to. I am using ubuntu server 6.10 installed by this Falko how to http://www.howtoforge.com/perfect_setup_ubuntu_6.10 Thanks in advance
You can create a cron job that uses the find command: http://www.howtoforge.com/forums/showthread.php?t=7040&highlight=/usr/bin/find
Thanks Falko So if I understand right then I make cron that will run once every month and the script should look like this Code: #!/bin/sh for file in "$( /usr/bin/find /.junk -type f -mtime +90 )" for file in "$( /usr/bin/find /.inbox -type f -mtime +90 )" for file in "$( /usr/bin/find /.trash -type f -mtime +90 )" do rm -f $file done exit 0 Am I right? This script will look over the whole system to find this folders (junk, inbox,trash)and in those folders that are found, will remove files that are older than 90 days?
The script should look like this: Code: #!/bin/sh for file in "$( /usr/bin/find /.junk -type f -mtime +90 )" do rm -f $file done for file in "$( /usr/bin/find /.inbox -type f -mtime +90 )" do rm -f $file done for file in "$( /usr/bin/find /.trash -type f -mtime +90 )" do rm -f $file done exit 0 Also, are you sure that /.junk, /.inbox, and /.trash are the correct folders?
Not shure... emails are in /var/www/webXX/user/XXX/Maildir/cur There are already read emails /var/www/webXX/user/XXX/Maildir/new There are unread emails /var/www/webXX/user/XXX/Maildir/.Junk/cur There are junk-spam emails /var/www/webXX/user/XXX/Maildir/.Trash/cur There are trash emails /var/www/webXX/user/XXX/Maildir/.Sent/cur There are sent emails So do yu think that kode shold look like this Code: #!/bin/sh for file in "$( /usr/bin/find /Maildir/cur -type f -mtime +90 )" do rm -f $file done for file in "$( /usr/bin/find /Maildir/new -type f -mtime +90 )" do rm -f $file done for file in "$( /usr/bin/find /Maildir/.Junk/cur -type f -mtime +90 )" do rm -f $file done for file in "$( /usr/bin/find /Maildir/.Trash/cur -type f -mtime +90 )" do rm -f $file done for file in "$( /usr/bin/find /Maildir/.Sent/cur -type f -mtime +90 )" do rm -f $file done exit 0
That would be difficult, because I have about 27 domains and each domain has about 15 emails, so I cant write that for ever user, because there can be new email user any minut and I will not be notified about new user and I would like to automate that prune system. Isnt there a way that system will look for all subfolders by that name and search files in that folders that are older than XX days?
Okey I try the script and wildcarts works But there is other problem, I have luck that I tested on test box Wel this is what happens. When I run the scrip the script did search for folders and also the files but script delete all never files until date I put in in my case that was 28 of october so I have no new files but files older than 17days, stays in folders. and that is the script I use Code: #!/bin/sh for file in "$( /usr/bin/find /var/www/web*/user/*/Maildir/cur -type f -mtime +17 )" do rm -f $file done for file in "$( /usr/bin/find /var/www/web*/user/*/Maildir/new -type f -mtime +17 )" do rm -f $file done for file in "$( /usr/bin/find /var/www/web*/user/*/Maildir/.Junk/cur -type f -mtime +17 )" do rm -f $file done for file in "$( /usr/bin/find /var/www/web*/user/*/Maildir/.Trash/cur -type f -mtime +17 )" do rm -f $file done for file in "$( /usr/bin/find /var/www/web*/user/*/Maildir/.Sent/cur -type f -mtime +17 )" do rm -f $file done exit 0 I tested on debian sarge, I belive on Ubuntu 6.10 is the same thing. Because Ubuntu 6.10 is in my production box.
Then try Code: /usr/bin/find /var/www/web*/user/*/Maildir/cur -type f -mtime [B][COLOR="Red"]-[/COLOR][/B]17 instead of Code: /usr/bin/find /var/www/web*/user/*/Maildir/cur -type f -mtime [B][COLOR="Red"]+[/COLOR][/B]17 Also have a look at Code: man find
I try - and + but, Its the same old files stays new were deleted. I did read man find, but dontknow how to help with that, I am not a programer so that is s little problem for me. But I saw there something about prune but didnt understand well. Could you help me.
OKey I did it I use this script Code: #!/bin/sh find /var/www/web*/user/*/Maildir/cur -type f -mtime +90 | xargs rm -f find /var/www/web*/user/*/Maildir/new -type f -mtime +90 | xargs rm -f find /var/www/web*/user/*/Maildir/.Junk/cur -type f -mtime +90 | xargs rm -f find /var/www/web*/user/*/Maildir/.Junk/new -type f -mtime +90 | xargs rm -f find /var/www/web*/user/*/Maildir/.Trash/cur -type f -mtime +90 | xargs rm -f find /var/www/web*/user/*/Maildir/.Sent/cur -type f -mtime +90 | xargs rm -f exit 0 And dont forget to make executable file I name it mailprune.sh, then I make crontab that run once a month Code: crontab -e Code: * * 1 * * /path/to/yourscript I wrote that if someone would need that also, and dont know how to do it. Thanks for your help Falko.
Is there a line I can put at the end of the script to recalculate the quota's, they don't appear to be refreshing?