How to delete X days old email
How to delete X days old email
Hi,
I have about 60 accounts on my Zimbra server. How can I delete all email which more than X days old?
I have about 60 accounts on my Zimbra server. How can I delete all email which more than X days old?
- jorgedlcruz
- Zimbra Alumni
- Posts: 2782
- Joined: Thu May 22, 2014 4:47 pm
How to delete X days old email
Hi vaarsn,
Hopefully, we have a strong community that do a lot of scripts, posts and everything, please check this URL and try to follow the steps and use the Script that our friend wrote for us year ago - http://pathakblogs.com/delete-old-mails ... m-scripts/ Let us know
Hopefully, we have a strong community that do a lot of scripts, posts and everything, please check this URL and try to follow the steps and use the Script that our friend wrote for us year ago - http://pathakblogs.com/delete-old-mails ... m-scripts/ Let us know
How to delete X days old email
It seems like it's working
Thanks
Thanks
How to delete X days old email
Hi Jorge,
It doesn't work. This is what I did:
1. I created *.sh file with the script above.
2. I careated /root/list file with IDs of my existing accounts and set THEDATE='date -d “2 days ago” +%m/%d/%y'
3. Launched it.
4. Got nothing.
I have about 10 acconts who has a letters more than 60 day old. I executed such script under root account. For the clarification, I'm using Zimbra 8.5.0
It doesn't work. This is what I did:
1. I created *.sh file with the script above.
2. I careated /root/list file with IDs of my existing accounts and set THEDATE='date -d “2 days ago” +%m/%d/%y'
3. Launched it.
4. Got nothing.
I have about 10 acconts who has a letters more than 60 day old. I executed such script under root account. For the clarification, I'm using Zimbra 8.5.0
- jorgedlcruz
- Zimbra Alumni
- Posts: 2782
- Joined: Thu May 22, 2014 4:47 pm
How to delete X days old email
Hi vaarsn,
I tried this Script and works, take a look, keep in mind this:
You only can delete like maximum 1000 emails at the same time, the script will ask if you want to execute more times if you have more than 1000 emails
You need to put the date like mm/dd/yy
If you want to use Inbox, type inbox (lower case)
This script will ask for each account, is not very batch, but works one by one
The code:
#!/bin/bash
#version .1
#
ZIMBRA_BIN=/opt/zimbra/bin
echo "Enter the username.:"
read THEACCOUNT
echo "Enter the time that you would like to delete messages up to, in mm/dd/yy format. Example 04/10/09:"
read THEDATE
echo "What folder would you like to delete these messages from?:"
read THEFOLDER
echo "You will now be deleting Messages from the $THEFOLDER folder up to $THEDATE for $THEACCOUNT."
echo "Do you want to continue? (y/N): "
read ADD
themagic ()
{
touch /tmp/deleteOldMessagesList.txt
for i in `$ZIMBRA_BIN/zmmailbox -z -m $THEACCOUNT search -l 1000 "in:/$THEFOLDER (before:$THEDATE)" | grep conv | sed -e "s/^ss*//" | sed -e "s/ss*/ /g" | cut -d" " -f2`
do
if [[ $i =~ [-]{1} ]]
then
MESSAGEID=${i#-}
echo "deleteMessage $MESSAGEID" >> /tmp/deleteOldMessagesList.txt
else
echo "deleteConversation $i" >> /tmp/deleteOldMessagesList.txt
fi
done
$ZIMBRA_BIN/zmmailbox -z -m $THEACCOUNT < /tmp/deleteOldMessagesList.txt >> /tmp/process.log
rm -f /tmp/deleteOldMessagesList.txt
echo "Completed. Run again for same user?"
read ADD
}
while expr "$ADD" : ' *[Yy].*'
do themagic
done
I tried this Script and works, take a look, keep in mind this:
You only can delete like maximum 1000 emails at the same time, the script will ask if you want to execute more times if you have more than 1000 emails
You need to put the date like mm/dd/yy
If you want to use Inbox, type inbox (lower case)
This script will ask for each account, is not very batch, but works one by one
The code:
#!/bin/bash
#version .1
#
ZIMBRA_BIN=/opt/zimbra/bin
echo "Enter the username.:"
read THEACCOUNT
echo "Enter the time that you would like to delete messages up to, in mm/dd/yy format. Example 04/10/09:"
read THEDATE
echo "What folder would you like to delete these messages from?:"
read THEFOLDER
echo "You will now be deleting Messages from the $THEFOLDER folder up to $THEDATE for $THEACCOUNT."
echo "Do you want to continue? (y/N): "
read ADD
themagic ()
{
touch /tmp/deleteOldMessagesList.txt
for i in `$ZIMBRA_BIN/zmmailbox -z -m $THEACCOUNT search -l 1000 "in:/$THEFOLDER (before:$THEDATE)" | grep conv | sed -e "s/^ss*//" | sed -e "s/ss*/ /g" | cut -d" " -f2`
do
if [[ $i =~ [-]{1} ]]
then
MESSAGEID=${i#-}
echo "deleteMessage $MESSAGEID" >> /tmp/deleteOldMessagesList.txt
else
echo "deleteConversation $i" >> /tmp/deleteOldMessagesList.txt
fi
done
$ZIMBRA_BIN/zmmailbox -z -m $THEACCOUNT < /tmp/deleteOldMessagesList.txt >> /tmp/process.log
rm -f /tmp/deleteOldMessagesList.txt
echo "Completed. Run again for same user?"
read ADD
}
while expr "$ADD" : ' *[Yy].*'
do themagic
done
How to delete X days old email
Hi Jorge,
Thank you for your suggestions. All I need is to delete all emails older than 90 days and delete them for all accounts which I have on a server. I want add that script as a cron job and run it e.g. once per month to cleanup all my accounts. I have a few accounts with more than 6K emails. Is that makes any sense? I'm not expert in bash scripting.
Thank you.
Thank you for your suggestions. All I need is to delete all emails older than 90 days and delete them for all accounts which I have on a server. I want add that script as a cron job and run it e.g. once per month to cleanup all my accounts. I have a few accounts with more than 6K emails. Is that makes any sense? I'm not expert in bash scripting.
Thank you.
- jorgedlcruz
- Zimbra Alumni
- Posts: 2782
- Joined: Thu May 22, 2014 4:47 pm
How to delete X days old email
Hi vaarsn,
The script that I provided you do this you only need to adjust a little bit and change the value of variables for the accounts that you want and the time that want to delete, keep in mind that Zimbra have the limit in 1000 emails per each command.
You can create different .sh scripts, for each account and inside of each .sh put $THEACCOUNT='user@domain.com' $THEFOLDER='inbox' and $THEDATE='mm/dd/yyyy' and then cron.
Try it and tell us but I'm pretty sure that it will works, only keep in mind the 1000 emails limit for each time that you execute the script.
The script that I provided you do this you only need to adjust a little bit and change the value of variables for the accounts that you want and the time that want to delete, keep in mind that Zimbra have the limit in 1000 emails per each command.
You can create different .sh scripts, for each account and inside of each .sh put $THEACCOUNT='user@domain.com' $THEFOLDER='inbox' and $THEDATE='mm/dd/yyyy' and then cron.
Try it and tell us but I'm pretty sure that it will works, only keep in mind the 1000 emails limit for each time that you execute the script.
How to delete X days old email
Hi,
It's working for me. Thanks, but as I said before this is what I need:
1. It must be fully automatic cron job.
2. This script must delete a messages from ALL accounts.
3. It shouldn't ask an exact date because all I need is to delete all messages older e.g. 20 days.
4. It should delete an old email from Sent, Trash etc. as well.
Regarding to 1000 messages limit it's not a problem. I just can run this script twice per day etc.
Can you help me with an requirements above?
Thank you in advance
It's working for me. Thanks, but as I said before this is what I need:
1. It must be fully automatic cron job.
2. This script must delete a messages from ALL accounts.
3. It shouldn't ask an exact date because all I need is to delete all messages older e.g. 20 days.
4. It should delete an old email from Sent, Trash etc. as well.
Regarding to 1000 messages limit it's not a problem. I just can run this script twice per day etc.
Can you help me with an requirements above?
Thank you in advance
- jorgedlcruz
- Zimbra Alumni
- Posts: 2782
- Joined: Thu May 22, 2014 4:47 pm
How to delete X days old email
I'm not a big expert in bash, I'm still learning. The script that I give to you can be put in a cron, you only need to change the questions and put the values that you want, and also you need to remove the magic bucle.
For remove from each account I'm still trying to make it.
For remove into Sent, Trash, etc you need to improve the script and add the line for each folder too.
I will try to made it, but it will be good idea if you try too and learn together
Maybe one member of the community can help us, but we can try us first.
I will let you know, try you too and let me know
For remove from each account I'm still trying to make it.
For remove into Sent, Trash, etc you need to improve the script and add the line for each folder too.
I will try to made it, but it will be good idea if you try too and learn together
Maybe one member of the community can help us, but we can try us first.
I will let you know, try you too and let me know
How to delete X days old email
Thank you I'll definitely try to make something my own. But please let me know once you'll find an exact solution