Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Perl / January 2006



Tip: Looking for answers? Try searching our database.

Finding the current user

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
James Reynolds - 05 Jan 2006 22:53 GMT
I know I can get this with `whoami`, but I was wondering if there was
a "Perl" way to find the user who executed the script.  I basically
want to make it so my script is executable by normal users, but
prints an error if it is not only the root user.

--

Thanks,

James Reynolds
University of Utah
Student Computing Labs
james@scl.utah.edu
801-585-9811
Sherm Pendley - 05 Jan 2006 23:04 GMT
> I know I can get this with `whoami`, but I was wondering if there  
> was a "Perl" way to find the user who executed the script.  I  
> basically want to make it so my script is executable by normal  
> users, but prints an error if it is not only the root user.

The $< variable has the real user id, and $> is the effective user id.

If you need more than the numeric user ID, have a look at:

    perldoc getpwnam
    perldoc User::pwent

sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
Sherm Pendley - 06 Jan 2006 00:52 GMT
> If you need more than the numeric user ID, have a look at:
>
>     perldoc getpwnam
>     perldoc User::pwent

D'oh! getpwnam() is a function (not a module), so that should be:

    perldoc -f getpwnam
    perldoc User::pwent

sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
James Reynolds - 06 Jan 2006 17:04 GMT
Thanks everyone!  I suppose I should learn all the special variables
after all...

James

>>If you need more than the numeric user ID, have a look at:
>>
[quoted text clipped - 10 lines]
>Cocoa programming in Perl: http://camelbones.sourceforge.net
>Hire me! My resume: http://www.dot-app.org
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.