I’m trying to write a small Perl script which creates a directory structure. To create the directories, I use the standard module File::Path, as follows:
make_path($directory,
{
owner => 'apache',
group => 'apache',
mode => 0500
}
);
When executing the script, the directory is created as wanted and the umask is set as expected, but both owner and group of the file are “root”. This is wrong, but where is the error? No error message is printed or given by the error-parameter.
Thanks in advance,
Jost
I just tried it and got the same outcome as you. I looked at the documentation:
…and no mention of ‘owner’ option. However, searching the latest version (2.08, AFAICT) documentation, and it’s there. Can you check the version of the module on your system?
If you’re not running 2.08, that might be the problem. I’m attempting to track down the changelog for the module right now, but having difficulty…
[ Later ]
OK, so here’s what you want to do:
Ultimately, the last line is the one you want to take note of. You can’t set the owner when you create it with that version of File::Path, but you can change it. The 33 in my example is the UID of the www-data user on my system; clearly, you want to change 33 to something more sensible for your system. Also, you will need to make sure that your script runs with privileges that are capable of doing this. For example, if you run this as a lowly user, it won’t work, but if you run it as root, the chown will work. You might want to find some middle ground there.