Solved

inventory script.

Posted on 2003-11-11
3
360 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

Independent Software Vendors: 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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Six Sigma Control Plans

726 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