Operating System - Linux
1830207 Members
2471 Online
109999 Solutions
New Discussion

How to force file permission of new files under certain directory

 
yyghp
Super Advisor

How to force file permission of new files under certain directory

I have a directory called /logs, which contains logs of application running by different users, like app.log.1, app.log.2, ...etc. no matter which user runs that application, such user can write/extend logs to the current log file, and will create a new log when the log file is filled up to 1MB. But the problem is that the application generate the log file with "-rw-r--r--" by default, with the owner who first creates that log file, then others can't extend that log file because no write permission.
How can I force the application generate the file with permission like "-rw-rw-rw-" ? or How can I force all new files to be "-rw-rw-rw-" under a certain directory?
Can ACL help?
Thanks!
4 REPLIES 4
Stuart Browne
Honored Contributor

Re: How to force file permission of new files under certain directory

I'd start by trying to set the umask prior to executing the application.

How is the application being launched? From a .profile?

If so, prior to the execution of the application, put a 'umask 002' (which should create files as -rw-rw-r--).

I'd couple this with setting the directory sgid (chmod g+s /logs), and setting the correct group on '/logs'.
One long-haired git at your service...
xyko_1
Esteemed Contributor

Re: How to force file permission of new files under certain directory

Hi yyghp,

the application that creates the file (log) may chmod just after creating it. I thing that's the easier way.

regards,
xyko
xyko_1
Esteemed Contributor

Re: How to force file permission of new files under certain directory

Hi Stuart and yyghp,

setting the umask solves the problem but it brings another one. umask will affect all files and directories during the shell session, not only the desired /log directory and for the scope of the application. So, one has to remember to set umask back to the defaults just after the application has finished.

regards,
xyko
Ross Minkov
Esteemed Contributor

Re: How to force file permission of new files under certain directory


> How can I force the application generate the file with permission like "-rw-rw-rw-" ?

One more thing -- log files writable by anybody... not a good idea.

Regards,
Ross