Summary: Cron & .profile

From: Joe Dietz (
Date: Fri Feb 24 1995 - 00:21:09 CST


I have a problem with cron on SunOS 4.1.3_U1 on a sparc20. We have a script
that runs fine--if run interactively by the user. In attempts to "cron" the
script the cron entry kicks off the script ok but we get errors. Some testing
shows that cron is running the script in "sh" and as the desired userid...but...
the environment variables like "path" are not getting set.

It would appear that cron is not reading the .profile before it runs the script.
Or cron is running the .profile and the environment is not being passed to the
script. Switching to different shells did not help...

I have another SA under SCO who has seen the same problem...There must be
something in comman with the way these scripts are build...or is it some detail
of cron we are missing...

00 00 * * * /bin/sh /
00 00 * * * /

Any and all ideas and comments welcome...thanks

The facts are that cron does not read any shell startup files like .cshrc,
.profile, or .login. It is necessary to manually call this startup files from
cron or the script being croned. Others suggested setting all path information
explicitly in the script--the solution we went with. Here are a few examples
folks sent. Understand that I did not test all of these options.

2 4 * * * (. $HOME/.profile;

from the man pages on crontab(5) (i.e. "man 5 crontab"):

     The command is run from your home directory with an arg0 of
     sh. Users who desire to have their .profile executed must
     explicitly do so in the command. cron supplies a default
     environment for every shell, defining HOME, LOGNAME, USER,
     SHELL(=/bin/sh), and PATH(=:/usr/ucb:/bin:/usr/bin).

 su - user -c /path_to_script/

I would recommend doing a ". $HOME/.profile" near the beginning of the
script or at least setting some minimal set of vars that are necessary.

A workaround was to make a shell wrapper which did two things...
1. Source the ".profile" or ".cshrc".
        NOTE : You must specify the home directory.
2. Start the script you want to execute.

Then cron the shell wrapper instead...

I guess a generic wrapper could be something like this:
vi /read_path
. /.profile
Then in cron you could have

0 12 * * * /read_path <executable_originally_in_cron>

00 00 * * * . /etc/profile; . .profile;

Thanks to all who replied....sorry if I missed anyone (Sean Ward)
etnibsd! (Steve Harris) (Eric William Burger) (Steve Ozoa) (Michael Sullivan) (Kohler R. P. (Robert))
Kambiz Aghaiepour <>
Tom Orban <>
Bob Mende Pie <> (Bob Shaw)
Neil Greene <>
citicds!cntower! (Arash Jahangir)
Robert Sargent <> (Tim Evans) (Terry Miesse)
Rex McMaster <> (met) (Bismark Espinoza) (Perry Hutchison) (David St. Pierre)

This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:10:17 CDT