How to set owner and permission for files/directory in directory in this case?

Hi.
My example:
I have a filesystem /log. Everyday, log files are copied to /log. I'd like to set owner and permission for files and directories in /log like that

chown -R log_adm /log/*
chmod -R 544 /log/*

It's OK, but just at that time. When a new log file or new directory is created in /log, it has owner and permisssion different with what I want . I don't want to execute these 2 commands above days by days to fix this.

I want every files and directories created in /log or copied to /log have owner: log_adm and permission:544. Is it possible. If yes, how ???

Thanks for read

How do the files get into /log? Is it a manual process or a script which is being run? In which case how is the script invoked: manually, batch scheduling etc.?

Once you know the answers to the above, I advise you to have a look into the "umask" command.

1 Like

Depending on your OS, the SUID bit on directories can do part of what you want. man chmod on FreeBSD:

But I don't think this feature is impemented anywhere nearly consistently across systems.

1 Like

Why the files are created with a different owner and permission is because they are created under a different user and umask.

1 Like

Yeah, files are copied to /log and directories are created in /log by some scripts ( scp and mkdir commands ). I can set the owner and permission by modifying the script, but it's a bit complex - not as simple as the example above. Of course it could be done, but I'm looking for a better solution. Thanks for your advice

Yeah the script which creates the files and directories has the owner: root, and files and directories created also have the owner : root, but I don't want the change the script's owner. I'm trying to find something useful in "umask"

You can use SetGID, but SetUID is ignored for directories on must Unix & Linux systems, as far as I know. (Except BSD, apparently. It definitely doesn't work on AIX.)

Can't you run the script as log_adm?

Alternatively, why can't you include the chown & chmod in the script?

1 Like

Most has laready been said but i'd like to question your premise: filemode 544 means "read and execute rights for the owner, readonly for his group and everybody else." Are you sure you want this? It is unusual to have a log file executed and i suppose it should be 644 instead. If any other user should be able to write into that directory you will need to open the filemode even some more: 664 or even 666.

I hope this helps.

bakunin

1 Like

Yes, but in fact files created by the script have many owners, not only log_adm like the example.

If there's no way, I'll use chown and chmod in the script.

Thanks. Now I can see that 544 is not a good choice, I'll fix this.

Also check out the +X mode which can come in handy to preserve execute bits on directories..

1 Like