0

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

3
  • Don't run the program as root! Jan 26, 2013 at 3:50
  • perhaps i should have specified. The program MUST be run as root.
    – rootchord
    Jan 26, 2013 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, 2013 at 7:19

2 Answers 2

3

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.

1
  • Does this help?
    – John Siu
    Feb 5, 2013 at 21:42
0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .