Skip to main content

Shell script to search for text in a file and copy that file

I have a mail server which running Kerio in CentOS 5.X. The total mail backup system is very simple. All the mails that pass in and out is automatically copied to a folder in that days name by Kerio in a folder called archive. So I have all the .eml files of all user' incoming and outgoing mails in a single folder for a particular day. I keep 3 months of those files on the server itself at any given point if time. The older ones I copy to an external USB hard disk. I also copy every day' email to a DVD as a compressed zip file. So I have two copies of all my mails for the last 3 years.

The recovery of mails happen very rarely as per user request and it used to take several days some times. Maximum time was used to search and find the particular user' mail from Terra bytes of mails. So I was searching for a script to search for the user' email address and copy the search result to a folder. I found the script which is as below.

find /path/to/mails  -name '*.eml' -exec grep -l "" {} \; -exec cp {} /path/to/copy \;

Thanks to Quintet for this suggestion


Popular posts from this blog

Create Great looking diagrams -

I was looking for an online diagram creating tool. Came across where I could create actually great looking diagrams without much of learning curve. The tool is 1. Very easy to use 2. Has drag and drop of elements to your diagram 3. Collaboration (which I have not tested). 4. Works from anywhere on a browser with Internet connection (I used it in Google Chrome on Linux Mint 10) When you click on the "Try it now" a new screen will open as below. You can either create a blank page to create a diagram from scratch or select from a bunch of samples and work on them to create one for your requirement. There are options to export the diagrams you created to SVG, JPEG, PNG and XML format once you register for free on the website. Once you register you can save the diagrams that you created in the site itself and retrieve it at a later time by logging into the website. I made three diagrams and it was real easy and simple. The site has two kind of pa

Kerio Connect - SQLLite journal.db error

Today I noted that the Keio Connect mail server had thousands of error.log files with 75MB size filled up in the server. As always Google gave the answer. The error looks some what like below. [10/Aug/2011 10:49:35] SQLiteDbWriteCache.h: write_thread - file '/path/to/file/<user>/.journal.db', SQLite error: code 1, error SQLITE_ERROR[1]: no such table: journal_temp The solution is as below 1. Delete the cache from the client's workstation 2. Delete the profile 3. Stop the server 4. Go to the server and navigate through the user's store folder 5. Delete the .journal.db (for Linux it is  find . -name "FILE-TO-FIND"-exec rm -rf {} \; ) 6. Start the server 7. Create a new profile for the clients workstation With help from Kerio Forum Cyberciti