Solved

inventory script.

Posted on 2003-11-11
3
354 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
  • 2
3 Comments
 

Author Comment

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

Accepted Solution

by:
kandura earned 500 total points
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now