Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

My first question, so be kind...

Basically, I have a folder that a user group has access to. This folder has a program in it that runs as root(via sudo) then outputs result files(xml files) to a subdirectory. Now, whenever the command is run it outputs the results with ownership of root(since that is who ran it). but i need any results created to be automatically changed to be owned by the group who owns the folder already. i tried using the setgid bit, but no luck. Any ideas?

EDIT: just some extra info. The program MUST be run as root. and i know i could set a cronjob or something, but i am looking for a more elegant solution.

Thanks in advance

share|improve this question
    
Don't run the program as root! –  Michael Hampton Jan 26 '13 at 3:50
    
perhaps i should have specified. The program MUST be run as root. –  rootchord Jan 26 '13 at 3:51
    
If it's not a stupid question, why must the files be owned by the owner of the directory? If it's so others can read them, that's got more to do with the permissions mask on the created file than the ownership; if it's so the owner can delete them, (s)he can do that anyway, because deletion privileges are controlled by directory access not file access. I ask because a lot of these questions start out as "I want to do Y" but are really "I want to achieve X by doing Y", when in fact Y is not the best way of achieving X. –  MadHatter Jan 26 '13 at 7:19
add comment

2 Answers 2

Add g+s to target dirdctory (assume done)

chown :usergroup target-directory
chmod g+s target-directory

With the above, all file create inside the target-directory, will have gid usergroup.

This does not work if file is created outside the target-directory, then moved into it. The gid WILL NOT change in this case.

touch <some-path>/test
mv <some-path>/test <target-directory>

test gid will not change in above case.

Look for temporary folder

It is very likely that the program in question created the file in another location / temporary folder, properly to prevent partial read. If that is the case, apply the g+s to that temporary folder will solve the problem.

However, DO NOT do this if the program is using system folders such as /tmp, /var/tmp for temporary folder. Change the temporary folder location first.

share|improve this answer
    
Does this help? –  John Siu Feb 5 '13 at 21:42
add comment

If you can get away with the files having the user root but a different group that your users are a member of check the commands "sg" and "newgrp". Running your program through sg will allow it to still be the root user but use a different group.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.