powerhouse has asked for the wisdom of the Perl Monks concerning the following question:

can I use chown to change a files ownership from root to the user/group like this:
chown("user:psacln","/file/path/to/loc");
I cannot get that to work... I searched for chown and found one, but that shows numbers only, I don't know how to get the username from any number.... in shell I do this:
chown user:psacln /file/to/loc
and that works.

I login to shell via root, so that I can move around on the whole server, so the owner of the files is root, so I need to change them to the username I am logged into, which I put at the top of the config file in var name: $_website_username

I don't know if the script on the page running can change roots files, but hope it can, I will appreciate any feedback you have for this.

thx,
Richard

Replies are listed 'Best First'.
Re: using chown to change file ownership
by ww (Archbishop) on Mar 16, 2010 at 22:43 UTC

    perldoc -f chown

    from which...

    chown LIST Changes the owner (and group) of a list of files. The +first two elements of the list must be the numeric uid and gi +d, in that order. A value of -1 in either position is interp +reted by most systems to leave that value unchanged. Returns th +e number of files successfully changed. $cnt = chown $uid, $gid, 'foo', 'bar'; chown $uid, $gid, @filenames;

    You might even be served well to read the whole thing.

Re: using chown to change file ownership
by jwkrahn (Abbot) on Mar 17, 2010 at 02:21 UTC
    I don't know how to get the username from any number.

    getpwuid and for the group name getgrgid.    To get the UID and GID from a name use getpwnam and getgrnam.

Re: using chown to change file ownership
by Anonymous Monk on Mar 16, 2010 at 22:40 UTC
    I think no. Well, maybe with help from chown, alternatively see perldoc -f chown