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


 
Thread Tools Search this Thread
Operating Systems AIX How to set owner and permission for files/directory in directory in this case?
# 1  
Old 05-25-2015
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
Code:
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
# 2  
Old 05-25-2015
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.
This User Gave Thanks to pilnet101 For This Post:
# 3  
Old 05-25-2015
Depending on your OS, the SUID bit on directories can do part of what you want. man chmod on FreeBSD:
Quote:
If mode ISUID (set UID) is set on a directory, and the MNT_SUIDDIR option
was used in the mount of the file system, then the owner of any new files
and sub-directories created within this directory are set to be the same
as the owner of that directory.
But I don't think this feature is impemented anywhere nearly consistently across systems.
This User Gave Thanks to RudiC For This Post:
# 4  
Old 05-25-2015
Why the files are created with a different owner and permission is because they are created under a different user and umask.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 05-26-2015
Quote:
Originally Posted by pilnet101
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.
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

Quote:
Originally Posted by Corona688
Why the files are created with a different owner and permission is because they are created under a different user and umask.
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"
# 6  
Old 05-26-2015
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?
This User Gave Thanks to CarloM For This Post:
# 7  
Old 05-26-2015
Quote:
Originally Posted by bobochacha29
Code:
chmod -R 544 /log/*

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
This User Gave Thanks to bakunin For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

How to set multiple ownership permission on a file/directory?

Hi, Any ideas to set multiple ownership permission on a file/directory on Solaris? I need a folder to have multiple ownership on the 2 nodes servers. The 2 nodes servers require to mount a SMBFS with different user ID. Please assist. Thanks. (6 Replies)
Discussion started by: freshmeat
6 Replies

2. UNIX for Dummies Questions & Answers

How to get the set of files size as a sum in a directory.

Hi, Can someone help me to get the complete files size (sum) over a perod time (1 day,2days)in a directory. eg: Directory :ABC I have a1,a2,a3 files are created in last 24 hours so I need to get the some of all these files. I am using the below find command but its giving me the... (1 Reply)
Discussion started by: gaddamja
1 Replies

3. UNIX for Dummies Questions & Answers

Group files by owner and show directory

Hello, i would like to find huge files and group them by owners. To find big files i use this command: ls -lR | sort -bnr +4 | head -n 75 which give me 75 biggest files, then i need to see in which subdirectory is every file. second thing i dont know is how to group those files by owner, could... (6 Replies)
Discussion started by: dealer1985
6 Replies

4. UNIX for Dummies Questions & Answers

How to display only Owner and directory/sub directory names under particular root

hai, I am new to Unix, I have a requirement to display owner name , directory or sub directory name, who's owner name is not equal to "oasitqtc". (here "oasitqtc" is the owner of the directory or sub directory.) i have a command (below) which will display all folders and sub folders, but i... (6 Replies)
Discussion started by: gagan4599
6 Replies

5. UNIX for Advanced & Expert Users

How UNIX admin set up this? how files of 744 of other owner can be removed by another owner?

Hi all, We have some files are under 744 permissions and the the owner is say owner1 and group1. Now we have another user owner2 of group2, owner2 can remove files of the owner1 and the permission of those files are 744, unix admin told us he did some config at his side so we can do that. ... (14 Replies)
Discussion started by: TheGunMan
14 Replies

6. Fedora

Find Files in Directory by Permission?

Hello. I need to write a script that lets the user pick a directory. Then, all files are looped through, and the ones with read-write (for current user I think) are listed. Ending with a count of those files, but that parts easy. What I'm confused about is the middle. So far I have ... (15 Replies)
Discussion started by: Feuyaer
15 Replies

7. Shell Programming and Scripting

to parse a directory and its subdirectories and find owner name of files

hi all, i need to capture all the files in a directory and its subdirectories that have owner name different than the root owner. for one file it is " stat -c %U filename " but i need to search for each and every file and record it. thanks in advance (14 Replies)
Discussion started by: vyasa
14 Replies

8. Shell Programming and Scripting

Sheel script to Delete a set of files from a given directory

I have a file <filestodelete> containing names of files to to be deleted from a directory <filesstore>. I want a script file which accptes the <filestodelete> and also the location of the directory(<filestore>) and deletes all files matching. Thanks in Advance.. (3 Replies)
Discussion started by: VardhiniVenkat
3 Replies

9. Shell Programming and Scripting

How to sort a set of files by date in a directory?

hi there, I have a directory which contents I can parse dynamically. I end up with a file list. I then want to display those files sorted by date, oldest files first. I have very very little PERL experience...Would anyone know how to do that ? Thanks in advance. (8 Replies)
Discussion started by: alexf
8 Replies

10. Shell Programming and Scripting

determine owner directory permissions from within the directory

From within a directory, how do I determine whether I have write permission for it. test -w pwd ; echo ? This doesn't work as it returns false, even though I have write permission. (4 Replies)
Discussion started by: Sniper Pixie
4 Replies
Login or Register to Ask a Question