Use the following predefined variables to get the user and group information belonging to the current process:
- $< - real user id (uid); unique value
- $> - effective user id (euid); unique value
- $( - real group id (gid); list (separated by spaces) of groups
- $) - effective group id (egid); list (separated by spaces) of groups
- This information applies only to Unix systems
- The values that theses variables hold are integers.
To get the user and group names, use '(getpwuid($<))' (for user information) and 'getgrgid($()' (for groups).
#-- check if running as root
print "Running as root!!\n" if ( $< == 0 );
#-- print username
print "Your username is " . (getpwuid($<)) . "\n";
#-- print groups information
@groups = split '\s', $(;
print "You belong to these groups: ";
print getgrgid($_) . " " foreach(@groups);