[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

get username of file owner?

John Fry

6/10/2005 9:46:00 PM

Hi,

I'd like to get the username of the owner of a file in my Ruby
program. Getting the uid is easy:

File.stat("testfile").uid -> 501

Anyone have a suggestion on how to get the actual username, like
"smith"?

I'm on Solaris without root and /etc/passwd does not list explicit
usernames.

Best,

John



1 Answer

Fredrik Fornwall

6/10/2005 10:57:00 PM

0

Once you have the uid of a user you can get the user name by using
the getpwuid function in the Etc module
(http://rubygarden.org/ruby/ruby?ProgrammingR...).

Example:

require 'etc'
uid = File.stat('testfile').uid
puts 'Owner name: ', Etc.getpwuid(uid).name

On Friday 10 June 2005 23.46, John Fry wrote:
> Hi,
>
> I'd like to get the username of the owner of a file in my Ruby
> program. Getting the uid is easy:
>
> File.stat("testfile").uid -> 501
>
> Anyone have a suggestion on how to get the actual username, like
> "smith"?
>
> I'm on Solaris without root and /etc/passwd does not list explicit
> usernames.
>
> Best,
>
> John