Solved

Help with Perl and removing info from a ypcat

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
windows 10 how make picture as desktop background 2 65
maven archtype selection in eclipse 1 57
fizzArray  challenge 1 96
only14 challenge 19 81
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

856 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