dr.jekyllandme has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I am writing a script that will find which user is executing the script.
I found 3 different ways to do this:
I noticed that for $ENV{ LOGNAME } and $ENV{ USER }, I can changes the variable value using setenv in csh and export in bash. But getpwuid's value always gives me the correct value. So should I go with getpwuid to get the correct user that is calling the script? Is there a better way? Thank you.#!usr/bin/perl use strict; use warnings; my $logname = $ENV{ LOGNAME }; print "\$logname = $logname\n"; my $user = $ENV{ USER }; print "\$user = $user\n"; my $pwuid = getpwuid( $< ); print "\$pwuid = $pwuid\n";
Back to
Seekers of Perl Wisdom