473,387 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

os.chown()

Hey everyone. I tried to use os.chown() in the following manner:

os.chown('filename', 'username', 'groupname')

I got an error, and when I googled for this function I realized that I
must pass the numerical uid and gid. My question is, is there a way for
me to change ownership based on the name instead of the number? Perhaps
there's a function that will let me lookup the uid from the username,
and the gid from the groupname?

Thanks :)

James

--
My blog: http://www.crazydrclaw.com/
My homepage: http://james.colannino.org/

"A well regulated militia being necessary to the security of a free
state, THE RIGHT of the people to keep and bear arms SHALL NOT BE
INFRINGED." --United States Constitution, Second Ammendment

Nov 11 '05 #1
3 10044
James Colannino <ja***@colannino.org> writes:
Hey everyone. I tried to use os.chown() in the following manner:

os.chown('filename', 'username', 'groupname')

I got an error, and when I googled for this function I realized that I
must pass the numerical uid and gid. My question is, is there a way
for me to change ownership based on the name instead of the number?
Perhaps there's a function that will let me lookup the uid from the
username, and the gid from the groupname?


You want pwd.getpwnam and grp.getgrnam.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Nov 11 '05 #2
Mike Meyer wrote:
You want pwd.getpwnam and grp.getgrnam.


Thanks. Hope my newbie questions haven't gotten on anybody's nerves yet ;)

James

--
My blog: http://www.crazydrclaw.com/
My homepage: http://james.colannino.org/

"A well regulated militia being necessary to the security of a free
state, THE RIGHT of the people to keep and bear arms SHALL NOT BE
INFRINGED." --United States Constitution, Second Ammendment

Nov 11 '05 #3
James Colannino <ja***@colannino.org> wrote:

Hey everyone. I tried to use os.chown() in the following manner:

os.chown('filename', 'username', 'groupname')

I got an error, and when I googled for this function I realized that I
must pass the numerical uid and gid. My question is, is there a way for
me to change ownership based on the name instead of the number? Perhaps
there's a function that will let me lookup the uid from the username,
and the gid from the groupname?


One way is:
os.system( 'chown username:groupname filename')

Are you doing this as root? The chown function is usually restricted to
root.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Nov 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Fronq | last post by:
Hi ! The entire (PHP-) world seems to have the same problem: Many providers let you upload as one user, lets say "ftpuser", yet then apache and your script will run as another user e.g....
2
by: Sean | last post by:
What is meant by: "CHOWN the entire casetracker folder to something that permits the server to write to it, such as apache.apache, or whatever your Webmaster recommends" - is that 700 or 777...Help...
7
by: LRW | last post by:
Sorry to crosspost, but I have no idea if this is more a PHP question of general Linux question. I have a script that makes changes to image files, montages them into a jpg, and creates a Web...
6
by: Ask Josephsen | last post by:
Hi NG If I write the following: <?php $file="myfile.JPG"; if ( getmyuid()==fileowner ( $file ) ) { chgrp ( $file, getmygid() ); chown ( $file, getmyuid() );
4
by: Perttu Pulkkinen | last post by:
I have a form handler script that creates a new folder for the files sent in the form. Move_uploaded_file transfers then puts those files there. But problem is that apache becomes automaticly...
7
by: Frank McCown | last post by:
This has probably been answered a million times, but I can't seem to find the answer. How can I change the owner of a directory using a Perl command? I know chown can be used with files, but it...
1
by: phil campaigne | last post by:
On Mon, 1 Mar 2004, phil campaigne wrote: >> Nigel J. Andrews wrote: >> > > >>> >On Mon, 1 Mar 2004, Phil Campaigne wrote: >>> > >>> >
20
by: pankajit09 | last post by:
Hello, Howto change the group and owner of a directory . I am doing this --> chgrp -R groupname directoryname but its not working .
2
by: Taorluath | last post by:
I just made a simple program to create files; I'm trying to get the hang of basic file manipulations. Whatever file my program makes, the owner of the file is "www-data," so I can't edit it using my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.