When I create a new file with a particular user user_a the default permissions for this user are -rw-r--r-- (644). I need to change the permissions for ONE PARTICULAR file from 644 to 646 when the file is created since this file will picked up by some other user_b with a scheduled job. The directory the file is located is called /apps/rawaexp and has the permissions 777.
I was thinking of changing .profile and to change the permissions for that file. Problem is that -as far as I understand- only is executed when the users logs on to UNIX. Also using umask does not seems to be much of help since it can only be used to revoke rights from a file.
For a single file, the script/application that drops the file in that directory should make sure that the file has the right permissions. umask affects all the subsequent file creations and so is not a proper solution here.
But, you can use the umask in the script that is creating the file to get the correct permissions.
Thanks for the answer. I forgott to mention that but we do not have access to the code which is putting the file there for political reasons. So I was hoping to get a spiffy trick for that.
Another approach.
Is it possible to inherit the permissions for a newly created file not from the creator but from the directory where the file is created in ?
I think "umask" is a completely wrong direction to go to here.
ou can use "chmod" to change the properties of a single file, yes? But you do not know when this file appears because it is created by a "black-box"-script, right?
OK, first solution: you create a wrapper script for the script creating the file so you can react upon it being finished. The black-box-script is to be only executed from this wrapper script:
Second solution: If the first solution is for any reason not possible you will have to watch for the file appearing and then change its filemode, right? Well, let a script do this somewhat boring task:
Save this script to a file, and execute it in background. It will have a look every 30 seconds if the file exists and if it does it will "chmod" it. 30 seconds is completely arbitrary, change that to your needs. If you do not need such a high resolution in time you could use cron instead of a "while"-loop:
This will execute cronscript.sh every five minutes if this is enough for you. Generally speaking the lesser the frequency is the less stress it puts onto the machine, so "every 10 minutes" is better than "every 5 minutes", etc.
Hi bakunin thanks for your time.
Your second approach will do the trick and I will suggest this to my manager. I will then try to schedule all three process is a resonable way 1.) creation of file test3 by black-box-script 2.) chmod of test3 by cronjob 3.) pick-up of modified file tes3 by SAP-Job
However I have done some more searching and was thinking of using a sticky-bit approach but unfortunately this does not seem to work for me either.
This is my situation:
-rwsrwxrwx 1 dmadmin dmadmin 15 Mar 19 11:03 change.sh
-rw-r--r-- 1 dmadmin dmadmin 5 Mar 19 10:53 test3
Where test3 is the file in question and change.sh is a script to change the mod of test3 by the user dmadmin. So in change.sh you will find something like:
My understanding of the sticky bit:
is that if I set the sticky-bit any user can now execute change.sh as the orginal user of the script (dmadmin) itself having all the permissions and should be able to change the mode of test3 to 777.
However if I run change.sh as a different user (otheruser in this case) I get the following error message:
/apps/otheruser > change.sh
chmod: can't change test3: Not owner
The reason for your problem is simple: out of security reasons shell scripts cannot be run in SUID mode per definition. I don't know HP-UX but this is so in every UNIX i came across so most probably this is true for HP-Ux too.
Anyways, you don't need a sticky bit, just make root to be the owner of the script and put the job in roots crontab. Then your script will be run under root authority.
Hi there!
I'm new to Unix and haven't done command line stuff since MS-Dos and Turbo Pascal (hah!),
I would love some help figuring out this basic command (what I assume is basic).
I'd like to add a User to the permissions of all files in a folder and all files in all subfolders, as well... (9 Replies)
Hi,
I have used expdp for datapump. The .dmp file is created by the "oracle" user.
my requirement is to make a zipped file of this .dmp file.
What i am trying to do is change the permissions of this .dmp file from 0640 to 0644 and then do a gzip and zip it. Is there any way i can change... (3 Replies)
Hi, I am creating a ksh script to search for a string of text inside files within a directory tree. Some of these file are going to be read/execute only. I know to use chmod to change the permissions of the file, but I want to preserve the original permissions after writing to the file. How can I... (3 Replies)
What command can i use to make sure that i cannot delete a file called backup (which i own) without affecting other permissions?
seems simple dont know how i forgot. :mad:
---------- Post updated at 07:59 PM ---------- Previous update was at 06:34 PM ----------
anyone ???
----------... (6 Replies)
Hello.
I have written a bash script that I am sharing with an OS X community I am a member of. The purpose of the script is to execute a series of commands for members without them having to get involved with Terminal, as it can be daunting for those with no experience of it at all. I have renamed... (4 Replies)
Hi all,
My UNIX box is HP UX - 11.11.
I have got a basic doubt. What are the global permissions for a file and directory?
I set the mask as 111 in my .profile. When I create a new file, it gets created withe -rw-rw-rw- permissions. A directory is created with drw-rw-rw- permissions. So, i... (7 Replies)
Hi,
I am a Unix Admin. I have to give the permissions to a user for creating new file in a directory in HP-Ux 11.11 system since he cannot able to create a new file in the directory.
Thanks in advance.
Mike (3 Replies)
Every time I copy files to a directory I am unable to edit the files. Why? The user is part of the group that has permissions to edit. The user can create and delete files but cannot edit files that are copied to the directory? :confused: (3 Replies)
Is there any way that I can use the ls command to view the permissions that a group has on a file.
I know ls -l file1 will list all the permissions for file1.
Would I have to use the following command: ls -l file1
Then grep or sed the output to retrieve what permissions the group has. (5 Replies)