1821053 Members
2648 Online
109631 Solutions
New Discussion юеВ

Umask for cron jobs

 
Phil Renner
New Member

Umask for cron jobs

Hi all! Does anyone know where the umask is set for cron jobs? We have umasks (002) set in the .profile and /etc/profile but when a job is run through cron it is using a umask of 022 to create files. HP is telling us to set the umask at the beginning of the cron job scripts but I would think there is a better, more permanent way to do this.
4 REPLIES 4
A. Clay Stephenson
Acclaimed Contributor

Re: Umask for cron jobs

Hi Phil,

Hp is telling you the truth. The environment for cron is intentionally very sparse. Not only will you need to set umask, but PATH and other environment variables as well.

One convention that you can use, if you have many common cronjobs is to include common settings in an external file and ". " to execute them at the beginning of every cron spawned script.

e.g.

ENV_STUFF=/usr/local/bin/cronenv.sh
if [ -r ${ENV_STUFF} ]
then
. ${ENV_STUFF}
fi

then /usr/local/bin/cronenv.sh might resemble this:
umask 027
PATH=/usr/bin:/opt/omni/bin:/opt/omni/lbin
USERVAR=goofy
export PATH USERVAR
# no exit statement

Regards, Clay


If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: Umask for cron jobs

Hi Phil:

Clay's suggestion of an "include" file for sourcing (the dot/blank/filename syntax) is an excellent one.

In fact, it helps to avoid the very annoying "not a typewriter" message which invariably gets mailed whenever a cron job executes and sources its user's $HOME/.profile to obtain environmental varibles.

Regards!

...JRF...
Bruce Regittko_1
Esteemed Contributor

Re: Umask for cron jobs

Hi,

Yes, HP is correct. The environment that cron supplies is very limited. The man page for crontab(1) shows what is supplied and mentions adding the .profile at the head of any cron scripts.

--Bruce
www.stratech.com/training

Re: Umask for cron jobs

Hi Phil:

We use to run a "su" command to a user, fron de crontab.

su - oracle74 -c "${SCRIPT}/start_stop.sh BGDWH STOP"

The .profile of this user set the env.
Nobody is perfect (Nobody)