[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 363
  • Last Modified:

inventory script.

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
morklebb
Asked:
morklebb
  • 2
1 Solution
 
morklebbAuthor Commented:
Is there a reason no one is looking at this?
0
 
kanduraCommented:
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
 
morklebbAuthor Commented:
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now