Perl setgrent Function

Advertisements


Description

This function Sets (or resets) the enumeration to the beginning of the set of group entries. This function should be called before the first call to getgrent.

Syntax

Following is the simple syntax for this function:

setgrent

Return Value

This function does not return any value.

Example

Following is the example code showing its basic usage:

#!/usr/bin/perl -w

while( ($name,$passwd,$gid,$members) = getgrent() ){
   print "Name  = $name\n";
   print "Password  = $passwd\n";
   print "GID  = $gid\n";
   print "Members  = $members\n";
}

setgrent();    # Set the beginnging of the group database;

print "Again reading /etc/passwd file\n";
while( ($name,$passwd,$gid,$members) = getgrent() ){
   print "Name  = $name\n";
   print "Password  = $passwd\n";
   print "GID  = $gid\n";
   print "Members  = $members\n";
}

endpwent;  #claose the database;
	
}

When above code is executed, it produced following result

Name  = root
Password  = x
GID  = 0
Members  = root
Name  = bin
Password  = x
GID  = 1
Members  = root bin daemon
Name  = daemon
Password  = x
GID  = 2
Members  = root bin daemon
Name  = sys
Password  = x
GID  = 3
Members  = root bin adm
Name  = adm
Password  = x
GID  = 4
Members  = root adm daemon
.
.
.
Name  = kvm
Password  = x
GID  = 36
Members  = qemu
Name  = qemu
Password  = x
GID  = 107
Members  = 
Name  = com
Password  = x
GID  = 501
Members  = 
Name  = webgrp
Password  = x
GID  = 502
Members  = com
Name  = railo
Password  = x
GID  = 495
Members  = 


Advertisements
Advertisements