Thursday, February 7, 2019

ZIMBRA Search keyword across all mailbox servers and users on a list.

The task is to search certain keywords on each mailbox at zimbra, so on the current version, 8.x, we can use the command:

zmmailbox -z -m username@zimbradomain.defined search "Keyword To Search"

So below is actually a sample search result with a keyword "I Love You"

search "I Love You" on user1@domain.com >> this is not part of zimbra search output, its part of the script to check what search keyword used because the keyword may be part of the email body and the result display what is the subject of the email where you can find the Keyword.

>>Output of search below<<

num: 1, more: false

       Id  Type   From                  Subject                                             Date
   ------  ----   --------------------  --------------------------------------------------  --------------
1. -21682  conv   Internal              How can you do that?                                    01/02/19 05:36



>>End of output<<

Going to search via command line, and I have 5 keywords to search and put it on a file at /home/user/keyword_file.txt

Keywords:
I love you
Why do that
Darling
Home
I did not do it

And I have a set of users to search, let say I have 10 users and put it on a file.

/home/user/userlist.txt

user1@domain.com
user2@domain.com and so on..

So below is a script that I have tried, as zimbra user and run it on one of the Mailstore.


#Below is to turn off splitting of multiple word on one line, like "I did not do it"
IFS=$'\n'

#If you want to check command execution
set -x

for keyword in `cat /home/user/keyword_file.txt`
do
for user in `cat /home/user/userlist.txt`
do
echo "search $keyword on mailbox $user"
zmmailbox -z -m $user search "$keyword"
done
done |tee -a /home/user/searchresult.txt
#End here

Just check on the searchresult.txt the results then.

If userslist contains a hundred, you can invoke screen so you can detach and re attach later if you need to check or usually if you did it remotely, so to avoid network disconnect.