Umask to generate files with rwx permissions for all


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Umask to generate files with rwx permissions for all
# 1  
Old 12-16-2016
Tools Umask to generate files with rwx permissions for all

i need my script1.sh to generate /tmp/temp.txt with full permissions i.e
Code:
-rwxrwxrwx   1 user1 users    23 Dec 16 10:52 /tmp/temp.txt

Code:
more script1.sh
umask 666
echo "hello">/tmp/temp.txt

But the script1.sh generates temp.txt with different permissions as shown below.

Code:
-rwxr-xr-x   1 user1 users  23 Dec 16 10:52 /tmp/temp.txt

I tried umask 600, 000 but they also did not help.

The reason i wish to give complete permissions is; so that other user executing script1.sh should not get the /tmp/temp.txt: Permission denied error.
# 2  
Old 12-16-2016
777 is not the magic sledgehammer to fix all permission problems. Stop that.

umask cannot grant execute permissions, not ever. They may not need execute permissions though, even if running it as a script.

What permissions does user2 actually want? Are they reading, writing, or executing the file?

umask 007 will give rw- permissions for user and group and nothing for anyone else, that should work for data files.

Last edited by Corona688; 12-16-2016 at 01:38 PM..
# 3  
Old 12-16-2016
This has nothing to do with shell scripting, but understanding how are set and works unix permissions...
Thread moved to more adequate forum : Beginners Q and A
This User Gave Thanks to vbe For This Post:
# 4  
Old 12-16-2016
Bug

Run my script with multiple users and it will fail for all users except the first.
# 5  
Old 12-16-2016
Quote:
Originally Posted by mohtashims
i need my script1.sh to generate /tmp/temp.txt with full permissions i.e
Code:
-rwxrwxrwx   1 user1 users    23 Dec 16 10:52 /tmp/temp.txt

Code:
more script1.sh
umask 666
echo "hello">/tmp/temp.txt

But the script1.sh generates temp.txt with different permissions as shown below.

Code:
-rwxr-xr-x   1 user1 users  23 Dec 16 10:52 /tmp/temp.txt

I tried umask 600, 000 but they also did not help.

The reason i wish to give complete permissions is; so that other user executing script1.sh should not get the /tmp/temp.txt: Permission denied error.
You do realize that umask only has an effect when creating a new file, don't you? To change the mode of an existing file, use chmod mode file...; not umask.

But, we know that the data you're showing us above was for a case where /tmp/temp.txt already existed and we know that your latest update to that file was not performed by the echo command you showed us. If the file had not already existed and you used the above commands, the output from ls -l would have been:
Code:
----------   1 user1 users  6 Dec 16 10:52 /tmp/temp.txt

not:
Code:
-rwxr-xr-x   1 user1 users  23 Dec 16 10:52 /tmp/temp.txt

This User Gave Thanks to Don Cragun For This Post:
# 6  
Old 12-16-2016
Just to make it explicitly clear (although implicitly alluded above): umask defines a MASK to be inverted & ANDed with the permissions supplied: the bits set in it will be turned OFF when a file is freshly created. man umask:
Quote:
Specifically, permissions in the umask are turned off from the mode argument to open(2) and mkdir(2).
These 2 Users Gave Thanks to RudiC For This Post:
# 7  
Old 12-16-2016
Quote:
Originally Posted by mohtashims
Run my script with multiple users and it will fail for all users except the first.
Could you answer any of my questions about what permissions are needed please?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Merge files and generate a resume in two files

Dear Gents, Please I need your help... I need small script :) to do the following. I have a thousand of files in a folder produced daily. I need first to merge all files called. txt (0009.txt, 0010.txt, 0011.txt) and and to output a resume of all information on 2 separate files in csv... (14 Replies)
Discussion started by: jiam912
14 Replies

2. UNIX for Dummies Questions & Answers

How to create a Group with rwx permission?

I want to create a GROUP with rwx permission. Also, I want to create a GROUP with root privileges, so that next time i create a user, I just need to add it to any of the groups and privileges automatically applied. please help. Thanks, Shouvanik (4 Replies)
Discussion started by: shouvanik
4 Replies

3. Shell Programming and Scripting

Setting default permissions without umask or cron jobs

I've got a number of people sending files to me in different directory structures, and users on many different groups who need access to these incoming paths. My problem is that umask assumes a default of 666 for files. No execute bit, meaning that my users can't even see the incoming folders.... (2 Replies)
Discussion started by: Karunamon
2 Replies

4. Shell Programming and Scripting

Can I make "touch" create executable files by manipulating umask?

I'm getting to grips with this concept of the umask. What I thought was, setting umask uga+rwx would result in creating files with all permissions for everyone. Seems not to be the case though. Read and write bits get set, but not the execute bit. Is there some gap in my understanding, or is... (2 Replies)
Discussion started by: tphyahoo
2 Replies

5. Solaris

consequence of chmod o-rwx ....

Hi guys I really want to know about the consequence of giving following command, on solaris 10 (sparc.) What would be effect of this on whole system and services running on system and what commands will be required exactly to get back the original perms . I recently tried above command... (3 Replies)
Discussion started by: upengan78
3 Replies

6. Shell Programming and Scripting

How to generate nested folder permissions

Hi expert, I would like to know how to generate file and folder ( including nested subfolder and files) permissions under oracle directory ? (8 Replies)
Discussion started by: skully
8 Replies

7. UNIX for Dummies Questions & Answers

Permission 711---RWX---X---X

I have a file with permisson 711; but when an other user run the program, it can't open. This is the message: /sbin/sh: ./myprogram: cannot open Can any1 tell me why please? Thanks! (6 Replies)
Discussion started by: bobo
6 Replies

8. Shell Programming and Scripting

how to generate a list of files

Hello people I need to find a way to generate a file that contains the names of all *.jpg files that were generated after a specific date The search should start in my current folder and recursively search inner folders It would be best to list the file names one below the other in the output... (3 Replies)
Discussion started by: jasongr
3 Replies

9. UNIX for Advanced & Expert Users

Changing default permissions -without "umask"-...

Hi! My question is this: Is it possible to change the default permissions in UNIX (666 for files and 777 for directories)?. I am not talking about using the command "umask". I mean, with the command "umask" you can modify permissions from a default permissions x. Is it possible to make... (4 Replies)
Discussion started by: chicoGuapo
4 Replies

10. AIX

umask for files created via nfs from windows stations

hello every body AIX 4.3.3, i want to set a write permission to files created by other users from windwos explorer or other AIX box in nfs files systems. how can i do this any helps will be appreciated (0 Replies)
Discussion started by: bousseta_rachid
0 Replies
Login or Register to Ask a Question