LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to set permissions to the newly generated files in the directory (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-set-permissions-to-the-newly-generated-files-in-the-directory-4175452015/)

vishnu15 02-27-2013 11:39 PM

How to set permissions to the newly generated files in the directory
 
I'm writing a shell script for MySQL database incremental backup using binary logs. The binary logs are collected in /usr/local/mysql/data/ directory. I have set all permissions to this directory data (chmod -R 777). When I did this, all files in the directory data were granted read,write and execute permissions.
But, when I flush logs, new logs get generated in data directory for which this permissions are not applied. Is there a way where I can apply the same permissions to this files as well. How can I do this?

shivaa 02-28-2013 12:35 AM

First thing is, you should not give 777 permission recursively to any directory, as it means that everyone who can access your system, will be able to access, modify, and alter the log files. So change it to:
Code:

~$ chmod -R 775 /usr/local/mysql/data
Second, any newly created file gets it's permissions assigned from what umask value is set for the file creator. But changing umask to 000 for file owner is not at all a good a recommended way. So just drop this idea.

Third, in your present case, I'd suggest you to apply SGID on the parant directory i.e. on /usr/local/mysql/data, and anyone whom you wish to allow to read content inside it, add to the main group of this directory.
Code:

~$ ls -ld /usr/local/mysql/data              # Checking owner and group of /usr/local/mysql/data
drwxrwxr-x  ....  testowner    testgroup .... /usr/local/mysql/data

~$ chmod g+xs /usr/local/mysql/data          # Adding SGID on directory

~$ usermod -G testgroup testuser1 testuser2  # Adding users to the main group i.e. testgroup

Using SGID, any newly created file inside it will inherit the main group of the directory. So the new log file will also have the same group as that of parant dir. has. Thus, anyone who's in this mail group i.e. testgroup, will be albe to read, write, and execute the content.


All times are GMT -5. The time now is 10:20 AM.