Solved

Help with Perl and removing info from a ypcat

Posted on 1997-04-03
1
307 Views
Last Modified: 2013-12-26
I want to find where each users home account is.. I am doing
a:

      #!/serve/bin/perl -w
        open(USERS, "user_list") || die "could not open file ($!)";
        while(<USERS>) {
            $person="$_";      
            $local = `ypcat passwd | grep $person`;
            print $local;
        }    

I want to remove the exta info that the ypcat gives me.  I tried doing
a $local =~ s/^$person//g; to start widdling away at the output of $person
but it doesn't work.

Any suggestions?

-Allen
0
Comment
Question by:allenm040397
[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
1 Comment
 

Accepted Solution

by:
trip040397 earned 200 total points
ID: 1292497
The answer is not to use ypcat. Use getpwnam() which returns an array, one element of which is the user's home dir. Exactly which element depends on the password file format. Grepping the passwd file like this is dangerous because, for instance, user pete and petew would both pass the grep for user pete.

You dont say which flavour of unix you are using and it is possible that getpwnam() is not available on your system in which case use:

open(PW, "passwd");
while (<PW>) {
  if (/^$person\:/) {
    @pwent = split (/:/);
  }
}

$home_dir = $pwent[4]

... it may not be item 4, depends on your passwd file format.

steve

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

717 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