Changing file permission upon creation in a directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Changing file permission upon creation in a directory
# 1  
Old 03-20-2010
Changing file permission upon creation in a directory

I want to change the permission of a file when it gets created in a particular directory. For instance, I have directory MyDir. Everytime a file gets created in that directory, I would like to change the permission to 777.
The context is that I have a 3rd party appication running as root. Only root can run it. It creates a file in directory ExecDir which another account should be able to execute (say user MyUser). But by default, a file created by root has permission rwxr--r--. I cannot also touch the code of this application since it is a 3rd party tool.

I know it's absurd.. but I hit a dead end...
# 2  
Old 03-20-2010
What OS are you running?

You will have to setup and run some process as the root user- a root crontab entry to find & chmod the files, that runs every X minutes, M-F will work

Code:
 0,10,20,30,40,50  * * * 1-5  /usr/bin/chmod  755 /path/to/files/*

You may have to get the sysadmin to set this up.

---------- Post updated at 08:00 ---------- Previous update was at 07:57 ----------

Note: you do realize the rwxr--r-- means anybody can copy the file and chmod it themselves, then execute it? As in you can write a shell script to do this.
# 3  
Old 03-20-2010
You can setup some advanced ACLs on the directory beyond the usual ugo-permission scheme.

In Linux and older Solaris file systems, the setfacl command allows you to create some rules for all files generated in a directory
For Solaris ZFS, you need to use the chmod +A command for advanced ACLs

Here is some help with the Solaris setfacl command and I think it should mostly translate for Linux
originalFileOwner=origOwner
originalGroupOwner=origGroup
altUser=targetUser


#Sets directories back to default with no special ACL
setfacl -s u::rwx,g::r-x,o:---,m:r-x ${appDir}
setfacl -s u::rwx,g::rwx,o:---,m:rwx ${appDir}/import
setfacl -s u::rwx,g::rwx,o:---,m:rwx ${appDir}/export




#Sets directory to allow for group ${altUser} to have read/execute access to ${appDir}
setfacl -s u::rwx,g::r-x,o:---,m:r-x,g:${altUser}:r-x ${appDir}


#Sets directories to all for user ${altUser} to have read/execute access to specific directories
# Permission: u::rwx,g::rwx,m:rwx,o:--- (standard chmod-based permissions of 770)
# Permission: u:${altUser}:r-x (Sets read/write/exec permissions to directory for user=${altUser} )
# Permission: d:u::rwx,d:g::rwx,d:m:rwx,dSmilie:--- (Sets default read/write/exec permissions for files created in this directory, mirrors 'u::rwx,g::rwx,m:rwx,o:---' permission)
# Permission: d:u:${originalFileOwner}:rwx,d:g:${originalGroupOwner}:rwx (Sets default read/write/exec permissions for files created in this directory for original file owners Unix user and group)
# Permission: d:u:${altUser}:r-x (Sets default read/exec permissions for files created in this directory for user=${altUser} )

setfacl -s u::rwx,g::rwx,m:rwx,o:---,u:${altUser}:r-x,d:u::rwx,d:g::rwx,d:m:rwx,dSmilie:---,d:u:${originalFileOwner}:rwx,d:g:${originalGroupOwner}:rwx,d:u:${altUser}:r-x ${appDir}/export


#Sets directories to allow for user ${altUser} to have read/WRITE/execute access to specific directories
# Permission: u::rwx,g::rwx,m:rwx,o:--- (standard chmod-based permissions of 770)
# Permission: u:${altUser}:rwx (Sets read/write/exec permissions to directory for user=${altUser} )
# Permission: d:u::rwx,d:g::rwx,d:m:rwx,dSmilie:--- (Sets default read/write/exec permissions for files created in this directory, mirrors 'u::rwx,g::rwx,m:rwx,o:---' permission)
# Permission: d:u:${originalFileOwner}:rwx,d:g:${originalGroupOwner}:rwx (Sets default read/write/exec permissions for files created in this directory for original file owners Unix user and group)
# Permission: d:u:${altUser}:rwx (Sets default read/write/exec permissions for files created in this directory for user=${altUser} )



setfacl -s u::rwx,g::rwx,m:rwx,o:---,u:${altUser}:rwx,d:u::rwx,d:g::rwx,d:m:rwx,dSmilie:---,d:u:${originalFileOwner}:rwx,d:g:${originalGroupOwner}:rwx,d:u:${altUser}:rwx ${appDir}/import
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. Shell Programming and Scripting

changing the file-name in a directory for all files matching a particular criteria

i have a directory which consist of multiple files out of which there are some files that has -e in their name. I want to write a script that will change all those file-name to -l example there are some files with name : file1-e.wav file2-e.wav file3-english-e.wav file-4-e.wav ... (3 Replies)
Discussion started by: mukulverma2408
3 Replies

3. Solaris

Changing file/directory owner

Hi , I want to change owner of files or folder from 23186 to dsadm, Present ------- -rw-r--r-- 1 23186 gdstage 10240 Oct 31 2007 BLTRS drwxrwxrwx 3 23186 gdstage 512 Sep 1 2010 sql Required as ----------- -rw-r--r-- 1 dsadm gdstage 10240 Oct 31 2007 BLTRS drwxrwxrwx 3 dsadm gdstage... (6 Replies)
Discussion started by: sridhardwh
6 Replies

4. UNIX for Dummies Questions & Answers

Changing file pemissions for all the files in a directory

For example, if i wanty to change the permission to 777 for all the files in a directory, is there any simpler way? Thanks (8 Replies)
Discussion started by: pandeesh
8 Replies

5. Solaris

Changing of syslog file path instead of /var/log directory

Hi Please let me know how can we change the syslog file path from /var/log to /a directory in solaris Regards (4 Replies)
Discussion started by: amity
4 Replies

6. Shell Programming and Scripting

Grep by range of date from file creation in directory

Hi Expert, Need your scripting and finding data so that it help me to find the culprit of this memory usage error. Data provided here is a sample. Process Snapshot directory: /var/spool/processes-snapshot webdev9o9% pwd /var/spool/processes-snapshot webdev9o9% ls -lrct -rw-r--r-- ... (3 Replies)
Discussion started by: regmaster
3 Replies

7. Shell Programming and Scripting

Changing file permission recursively

I have a directory named DIR. The contents of the directory is something like: a.sh b.sh cghsk.sh assjsjkd gdshddll DFG/ ... ... Where only DFG/ is a folder. I want to grant execute permission to all(a+x), for all the files directly under the DIR directory except the files that... (4 Replies)
Discussion started by: proactiveaditya
4 Replies

8. Shell Programming and Scripting

how to exclude file when changing permission

I have files as below: erf100.sh erf101.sh erf102.sh erf103.sh erf104.sh erf105.sh I can easily change permission of all files to 755 by issuing command below: chmod 755 erf*.sh; how do i change permission of all files but excluding file erf102.sh? thanks best regards (2 Replies)
Discussion started by: khchong
2 Replies

9. UNIX for Dummies Questions & Answers

granting permission to file/directory to a specific user

hello, I would like to grant full access to a directory which is owned by root and the web application that created it. I have though of adding the permission to the whole world, but for security reason I would like to grant it to one more user. I have tried this 'chmod -U newUser+wrx... (2 Replies)
Discussion started by: run123
2 Replies

10. UNIX for Dummies Questions & Answers

Changing Creation Date to a Prespecified Date of a File In Unix

Dear Expert, Is there a command to do that in Unix? In such a way that we don't need to actually "write" or modified the content. -- monkfan (4 Replies)
Discussion started by: monkfan
4 Replies
Login or Register to Ask a Question