The getgrnam function retrieves the group file entry corresponding to a particular group name. : getpwnam « System Functions « Perl






The getgrnam function retrieves the group file entry corresponding to a particular group name.

      

# The syntax is (gname, gpasswd, gid, gmembers) = getgrnam (name); 

#!/usr/local/bin/perl 

$name = "grp1"; 
if (!(($gname, $gpasswd, $gid, $gmembers) = getgrnam ($name))) { 
    die ("Group $name does not exist.\n"); 
} 
$userids = 0; 
while (1) { 
    last if ($gmembers eq ""); 
    ($userid, $gmembers) = split (/\s+/, $gmembers, 2); 
    printf (" %-20s", $userid); 
    $userids++; 
    if ($userids % 3 == 0) { 
        print ("\n"); 
    } 
} 
if ($userids % 3 != 0) { 
    print ("\n"); 
} 

   
    
    
    
    
    
  








Related examples in the same category

1.Test a UNIX password
2.To display all the /etc/passwd fields for users passed on the command line
3.Values Returned by getpwnam