Reputation: 13
I'm looking to simply open and write a new file, then have it owned by another user (while running as root). The file creation works alright but the file still ends up being owned by root. I'm using:
doc="text"
uid=Etc.getpwnam("#{$user}").uid
File.open("#{$file}", 'w') {|f|
f.write(doc)
f.chown($uid,$uid)
}
Any help is greatly appreciated :)
Upvotes: 1
Views: 1014
Reputation: 9424
Only a process with superuser privileges may change the owner of a file. [RubyDocs]
Try running ruby with sudo
.
EDIT
Second argument should be group ID. Not user ID.
EDIT 2
Turned out to be the globals. My heart has never been happier. Please see comments.
Upvotes: 1