Solved

inventory script.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 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

11 Experts available now in Live!

Get 1:1 Help Now