LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Finger command to list all the user names (https://www.linuxquestions.org/questions/programming-9/finger-command-to-list-all-the-user-names-581767/)

narainhere 09-03-2007 01:49 AM

Finger command to list all the user names
 
Hi all,
I am having a perl script which should mail a report.I need to figure out the Real names for the user-id's .The problem is I need to retrieve the real-names for all the user-id's on the server.Is there a way to do this?

adam_blackice 09-03-2007 02:38 AM

hello

i think the proper way is to go to the /etc/passwd file and then extract the fields you want and then pass that to variable and use it to get the list if the real name

here is the code that u will use

Code:

#Author: Black-Ice
#Date: 20/6/2007
#!/usr/bin/perl -w
use strict;

my $file = "/etc/passwd";

open (han1, "$file") || die  "error opening file: $!";


my @newrecords = ;

foreach (@newrecords) {

my @columns = split /:/;

my $username = $columns[0];
my $x = $columns[1];
my $userid = $columns[2];
my $groupid = $columns[3];
my $realname = $columns[4];
my $homedir = $columns[5];
my $shellpath = $columns[6];

#then u can echo the field that you want to disply

either u can do it throw a shell script and that will be good too


Code:

cat /etc/passwd | cut -d : -f "the field of the real name in the /etc/passwd file "

ghostdog74 09-03-2007 04:05 AM

Quote:

Originally Posted by adam_blackice (Post 2879336)
Code:

cat /etc/passwd | cut -d : -f "the field of the real name in the /etc/passwd file "

no need for cat
Code:

cut -d":" -f5 /etc/passwd

adam_blackice 09-03-2007 04:56 AM

you are right but i used to do it like that :)


All times are GMT -5. The time now is 10:17 AM.