Solved

Help with Perl and removing info from a ypcat

Posted on 1997-04-03
1
297 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
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 122
method notes when mouse over in eclipse 5 87
format the code in java 6 93
wait notify demo infinite loop 3 110
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

777 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