Solved

Help with Perl and removing info from a ypcat

Posted on 1997-04-03
1
286 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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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 gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 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

14 Experts available now in Live!

Get 1:1 Help Now