Operating System - HP-UX
1833230 Members
2673 Online
110051 Solutions
New Discussion

Re: I need a umask that will give me perms -r-xr-xr-x (For files)

 
RAC_1
Honored Contributor

I need a umask that will give me perms -r-xr-xr-x (For files)

I am going mad about this. Tried different combinations. Is it possible to get perms as follows.

-r-xr-xr-x
What umask setting will give me this??
I tried /usr/bin/umask "a=rx"
/usr/bin/umask "u=rx,g=rx,o=rx"

Anil
There is no substitute to HARDWORK
10 REPLIES 10
Cheryl Griffin
Honored Contributor

Re: I need a umask that will give me perms -r-xr-xr-x (For files)

umask won't give you the executable bit.
You can change the bits that are there but not add executable.

See
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=594537
"Downtime is a Crime."
Victor BERRIDGE
Honored Contributor

Re: I need a umask that will give me perms -r-xr-xr-x (For files)

Hi
umask 222 will do this...
but to see it you would need a file with 777 perms that you copy, as cheryl said umask will not add permissions but restrict...
So no hope to create a file natively with 555 perms...

All the best
Victor
john korterman
Honored Contributor

Re: I need a umask that will give me perms -r-xr-xr-x (For files)

Hi,
I am afraid that it is not possible with umask. My understanding of that is that it can only take something away, not add.
If you set the umask to remove nothing, e.g.:
# umask 000
and try to create a plain file, you will see that it gets the perissions rw-rw-rw-, which is the default maxmimu, so to say. By setting umask to something else than 000 can only take away permissions.

regards,
John K.
it would be nice if you always got a second chance
A. Clay Stephenson
Acclaimed Contributor

Re: I need a umask that will give me perms -r-xr-xr-x (For files)

Chill out; this ain't gonna happen. There are two components in play when setting the mode of a file on creation. 1) The mode argument and 2) the umask which then "subtracts" (it's not really subtraction but close enough) from the mode. Unless the mode starts out with the execution bit set there is nothing to "subtract". The shell's default mode for regular files is rw-rw-rw- and rexrwxrwx for directories. If you were coding in C then setting the execution bit on creation is a one-step process but in the shell it requires an explicit chmod after the file is created.

Man 2 creat for the details.
If it ain't broke, I can fix that.
Fred Ruffet
Honored Contributor

Re: I need a umask that will give me perms -r-xr-xr-x (For files)

A. Clay Stevenson,

It's the second message I see from you saying it is not really "substract". Why are you saying that ? What is the difference ?

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Ralph Grothe
Honored Contributor

Re: I need a umask that will give me perms -r-xr-xr-x (For files)

If you consider directories also as files (in Unix (almost) everything is a file) at least the mkdir command offers an -m switch that allows you to set mode bits already during creation.
Apart from that you don't have to confine yourself to C for that feature.
Any decent (system) programming language should give you this freedom.
E.g. if you have Perl installed consult
perldoc -f open
perldoc -f sysopen
perldoc perlopentut
Madness, thy name is system administration
Ralph Grothe
Honored Contributor

Re: I need a umask that will give me perms -r-xr-xr-x (For files)

I think he calls at not quite subtracting because it's really a nand operation,
so no real mathematical arithmetics I suppose.
Madness, thy name is system administration
Ralph Grothe
Honored Contributor

Re: I need a umask that will give me perms -r-xr-xr-x (For files)

Forgot, if you insist on creat() syscall
but want the higher level comfort of Perl
see also
perldoc POSIX
Madness, thy name is system administration
A. Clay Stephenson
Acclaimed Contributor

Re: I need a umask that will give me perms -r-xr-xr-x (For files)

The actual operation is that every bit in umask is not'ed and then the result is AND'ed with the mode to produce the actual creation mode.

---------------------------------------
#include

int main()
{
int Mode = 0777,Umask = 0111,Result_Mode = 0;

(void) printf(\n"Mode = %o Umask = %o ",
Mode,Umask);
Result_Mode = Mode & ~(Umask);
(void) printf("Resulting Mode = %o\n",Result_Mode);
return(0);
} /* main */

----------------------------------------

If it ain't broke, I can fix that.
Ralph Grothe
Honored Contributor

Re: I need a umask that will give me perms -r-xr-xr-x (For files)

in lack of a C compiler

$ perl -e 'printf"%o\n",0777&~0111'
666
Madness, thy name is system administration