Results 1 to 5 of 5
I am in need of scripting help; bash, perl, python... not sure which would get it done best.
I've been thrown into a system admin setting running linux with very ...
- 05-03-2010 #1Just Joined!
- Join Date
- Feb 2010
- Posts
- 7
Complex search and retrieve - bash, python, perl??
I am in need of scripting help; bash, perl, python... not sure which would get it done best.
I've been thrown into a system admin setting running linux with very few linux-specific skills. I've done some rudimentary coding in Java and Cpp before, but this is a bit out of my league.
Your help is greatly appreciated! Any explanation you could give would be icing on the cake!
SITUATION:
I need to search through multiple mult-level folders to pull emails between certain users. I need to recurse into any subdirectories (mail folders) also.
The structure (with regexs) looks like: /backup/nightly.[0-9][0-9]/fc/[a-zA-Z]*/.mailbox/*
I'm looking to match any three (or more) of ten users included in an email, which are all lowercase names of differing lengths.
From what I've read, I'm guessing I'll have to:
- use ls to get the list of file (mail) locations
- pipe it to grep to see the results have any matches to the users
- then pipe that to rsync to copy the files to another location.
I'm just not sure how to implement this in its entirety. Nor if my thought process is even right... :/
I'm guessing it may be easier to do in perl or python, but i haven't the slightest clue where to start with that.
Thanks again for your help and direction!
- 05-03-2010 #2Just Joined!
- Join Date
- Feb 2010
- Posts
- 7
any hints are more than welcome, too!
- 05-03-2010 #3Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Instead of the 'ls' command, you are probably better off using 'find' with grep instead. Example:
This example will return the specified directories. If you want files instead, just change the -type d option of the find command to -type f instead.Code:find /backup -type d -print | grep '/backup/nightly.[0-9][0-9]/fc/[a-zA-Z]*/.mailbox/*'
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 05-03-2010 #4Just Joined!
- Join Date
- Feb 2010
- Posts
- 7
Thanks; I've used both methods to get a list of folders/files, though the ls seems much much faster...
either way, after generating this list of files, how do I search through them for a certain string and copy the matching files to another folder? Is there a way in bash?
Thanks!
- 05-03-2010 #5Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Bash is a scripting/programming language. There isn't much you cannot do with it, especially when you do it in conjuction with tools such as awk, sed, grep, etc. You really should get a book on the subject (there are a number of good ones you can get from Amazon or down at your local Borders/B&N), or spend a lot of time reading the man pages (not particularly helpful for the newbie).
So, the short answer is "Yes, you can do this with bash.", but because it is a language, there are a number of methods which will give you the same results.Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote