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 "xyz@example.com" {} \; -exec cp {} /path/to/copy \;

Thanks to Quintet for this suggestion

Comments

Popular posts from this blog

Create Great looking diagrams - Gliffy.com

I was looking for an online diagram creating tool. Came across Gliffy.com 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

How to Configure Samba to Share a Folder with Two Users on Ubuntu (with Read/Write and Read-Only Permissions)

Samba is a file sharing software that allows you to share files between Linux and Windows computers. It is a popular choice for home users and businesses alike. In this article, we will show you how to configure Samba to share a folder with two users, one with read/write permissions and one with only read permissions, on Ubuntu. Prerequisites Before you begin, you will need the following: A Linux computer running Ubuntu Two user accounts A shared folder Steps Install Samba. sudo apt install samba Create the shared folder. sudo mkdir /shared Configure Samba's global options. Open the Samba configuration file /etc/samba/smb.conf in a text editor. Add the following lines to the [global] section: security = user passdb backend = tdbsam This will set the security mode to user , which means that users will be authenticated using their local Linux accounts. The passdb backend option specifies the database that Samba will use to store user passwords. In this case, we are using the tdbsa

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