Deleting Main User E-mails - Guideline Needs Update

orkinoks

Verified User
Joined
Dec 24, 2010
Messages
75
Hi,
I tried to delete main user e-mails using this guideline.
http://help.directadmin.com/item.php?id=433
The command to delete the main user e-mails is :
rm -f `find /home/$i/Maildir -mtime +${OLD_THAN_DAYS} | grep -E '/cur/|/new/'`

But I get "line 12: /bin/rm: Argument list too long" error. Clearly there is a directory with more number of e-mails then rm can handle.

According to this guideline :http://help.directadmin.com/item.php?id=327
We need to be using find . -type f -delete

Based on this two info, could someone re-write the line which will delete main user e-mails and confirm that it is all correct before I do something horrible
 
You need to make script to do that, like the following I did:
To works fine, First must complete that :p
Code:
find $directory -type f -name '*' -exec mv
{} $directory2/. \;
#!/bin/sh

#Deletes emails older than this number of days
OLD_THAN_DAYS=30

for i in `ls /usr/local/directadmin/data/users`; do
{
       if [ ! -d /home/$i/Maildir ]; then
               continue;
       fi

       rm -f `find /home/$i/Maildir -mtime +${OLD_THAN_DAYS} | grep -E '/cur/|/new/'`

find $directory -type f -name '*' -exec mv {} $directory2/. \;

};
done;
exit 0;
 
I got
find: missing argument to `-exec'
clean_mail.sh: line 2: {}: command not found
with your script.
 
Cause he did pasted not correctly, use this:

Code:
#!/bin/sh
find $directory -type f -name '*' -exec mv {} $directory2/. \;

#Deletes emails older than this number of days
OLD_THAN_DAYS=30

for i in `ls /usr/local/directadmin/data/users`; do
{
       if [ ! -d /home/$i/Maildir ]; then
               continue;
       fi

       rm -f `find /home/$i/Maildir -mtime +${OLD_THAN_DAYS} | grep -E '/cur/|/new/'`

find $directory -type f -name '*' -exec mv {} $directory2/. \;

};
done;
exit 0;

Is just needed to bring second line as continue of the first.

Regards
 
Thanks @SeLLeRoNe
I told you guys you must com pleat at first. So I think you got the error because of file size.

Use following code, It'll fix your problem. :cool:
Code:
#!/bin/sh
find $directory -type f -name '*' -exec mv {} $directory2/. \;

#Deletes emails older than this number of days
OLD_THAN_DAYS=30

for i in `ls /usr/local/directadmin/data/users`; do
{
       if [ ! -d /home/$i/Maildir ]; then
               continue;
       fi

       rm -f `find /home/$i/Maildir -mtime +${OLD_THAN_DAYS} | grep -E '/cur/|/new/'`

find /home/$i/Maildir -type f -name '*' -exec rm {} \;

};
done;
exit 0;
 
Hi Sellerone,
thanks for the warning, I did not notice the mistake.
However I got
line 13: /bin/rm: Argument list too long
error with your script too.

Cause he did pasted not correctly, use this:

Code:
#!/bin/sh
find $directory -type f -name '*' -exec mv {} $directory2/. \;

#Deletes emails older than this number of days
OLD_THAN_DAYS=30

for i in `ls /usr/local/directadmin/data/users`; do
{
       if [ ! -d /home/$i/Maildir ]; then
               continue;
       fi

       rm -f `find /home/$i/Maildir -mtime +${OLD_THAN_DAYS} | grep -E '/cur/|/new/'`

find $directory -type f -name '*' -exec mv {} $directory2/. \;

};
done;
exit 0;

Is just needed to bring second line as continue of the first.

Regards
 
I don't know why but this one also gives argument list too long error.
As of my understanding, we have get rid of rm command between if - fi.

Thanks @SeLLeRoNe
I told you guys you must com pleat at first. So I think you got the error because of file size.

Use following code, It'll fix your problem. :cool:
Code:
#!/bin/sh
find $directory -type f -name '*' -exec mv {} $directory2/. \;

#Deletes emails older than this number of days
OLD_THAN_DAYS=30

for i in `ls /usr/local/directadmin/data/users`; do
{
       if [ ! -d /home/$i/Maildir ]; then
               continue;
       fi

       rm -f `find /home/$i/Maildir -mtime +${OLD_THAN_DAYS} | grep -E '/cur/|/new/'`

find /home/$i/Maildir -type f -name '*' -exec rm {} \;

};
done;
exit 0;
 
I don't know why but this one also gives argument list too long error.
As of my understanding, we have get rid of rm command between if - fi.
Did you paste on your command run?
If so, yes it is. Don't anymore and follow the bellow instruction:

1. type the following code to make a file
Code:
nano delmail
2. copy the following cod :
Code:
#!/bin/sh

OLD_THAN_DAYS=30

for i in `ls /usr/local/directadmin/data/users`; do
{
       if [ ! -d /home/$i/Maildir ]; then
               continue;
       fi

       rm -f `find /home/$i/Maildir -mtime +${OLD_THAN_DAYS} | grep -E '/cur/|/new/'`

find /home/$i/Maildir -type f -name '*' -exec rm {} \;

};
done;
exit 0;
3. press crtl + o to save file
4. press crtl + x to exit
5. type the following code
Code:
chmod 755 delmail
./delmail
 
Back
Top