Solved

inventory script.

Posted on 2003-11-11
3
359 Views
Last Modified: 2010-03-04
I wish to make an inventory from data in various files in users home directories.
Assuming the home directories are in /home.. I want to process each directory, for a file that will exist.
In user foo I would want to check 3 files, /home/foo/dir1/file, /home/foo/dir2/file, /home/foo/dir3/file for a string
say, "^emailname=", the trick is that there might be 1 of 3 or more different version of the file under the 3 directories
for the user but only one of them would define emailname=blah the others would just be blank. So for example
dir1/file might contain "emailname=" and dir2/file might have "emailname=blah" and then dir3/file would again
be "emailname=", only 1 of the 3 would have a value for emailname. I need to then find which of the 3 has the
value and write that to a file in the /home directory for example:
username: foo
emailname: blah
username: foo1
emailname: blahblah
etc.
The file in each users directory is copied from a template and will be the same default blank values until they
have picked one of the directories then that particular file will be populated with various values.
0
Comment
Question by:morklebb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:morklebb
ID: 9741049
Is there a reason no one is looking at this?
0
 
LVL 18

Accepted Solution

by:
kandura earned 500 total points
ID: 9743515
here's the short answer to your question:

egrep -r '^emailname=.+' * | perl -nle 'print qq,username:$1$/emailname:$2, if m,/home/([^/]+)/.*emailname=(.+),'  > /home/inventory.txt

I don't think anyone answered your question yet because you're not making it obvious what your problem is writing the script in perl.
IMHO it feels a bit like you want someone to write the script for you, and that's not what we're here for.
The experts here want to help you by answering questions, not by doing your work for you. But you're lucky, I just did :-)

HTH,
Kandura
0
 

Author Comment

by:morklebb
ID: 9749056
I had several different ideas but most of mine were in shell scripting. You did however provide
more than enough information through example that I have been able to learn from it and make
it work.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

736 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question