Help - Search - Members - Calendar
Full Version: Seemingly Simple Cron Question: Any Ideas?
Linuxhelp > Support > Technical Support
Hi all,

Is there a way to specify default umask settings for shell scripts run from a user's crontab?

Every time a script creates a file or directory, it's perms are rw-r--r--, despite my attempts to change to 'umask 002' (set in the user's .bashrc and /etc/profile).

Any ideas how I might get all cron scripts run by a single user to create files with perms of rw-rw----?
How umask works....

If you type the command umask at the command prompt for the user (prior to any changes), it will probably say 0022 ... forget about the first 0 ... and the last 3 digits would subtract from 666 permissions (rw-rw-rw-) and make them 644(rw-r--r--) for file creation ... if you use umask 0006, it should change 666 to 660(rw-rw----) when creating files.

(umask can have 4 characters instead of 3 ... everyone forgets the first 0 and some systems will make a 002 be 0020 instead of 0002 ... and in most versions of *nix 3 digits will still work).
Here is how you can test umask .... set your umask with the command:

umask 0006

Then go to a directory you can write in ... I would just pick my home directory ...

Then issue the command:

touch file_permissions

Check the permissions with the command:

ls -al | grep permissions

Should be permissions of 660 (rw-rw----)

Then make a directory with the command:

mkdir dir_permissions

Then look at both the file and the directory:
ls -al | grep permissions

The directory will have 771 (rwxrwx--x) permissions .... for some reason an x is always added
Then just put either umask 0006 in either the user's .bashrc (or .bash_profile) ... or you can put umask 0006 in the script you are running.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2017 Invision Power Services, Inc.