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 /script.sh
00 00 * * * /script.sh
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; my_script.sh)
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/script.sh
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:
Then in cron you could have
0 12 * * * /read_path <executable_originally_in_cron>
00 00 * * * . /etc/profile; . .profile; script.sh
Thanks to all who replied....sorry if I missed anyone
firstname.lastname@example.org (Sean Ward)
email@example.com (Steve Harris)
firstname.lastname@example.org (Eric William Burger)
email@example.com (Steve Ozoa)
firstname.lastname@example.org (Michael Sullivan)
email@example.com (Kohler R. P. (Robert))
Kambiz Aghaiepour <firstname.lastname@example.org>
Tom Orban <email@example.com>
Bob Mende Pie <firstname.lastname@example.org>
email@example.com (Bob Shaw)
Neil Greene <firstname.lastname@example.org>
email@example.com (Arash Jahangir)
Robert Sargent <firstname.lastname@example.org>
email@example.com (Tim Evans)
firstname.lastname@example.org (Terry Miesse)
Rex McMaster <email@example.com>
firstname.lastname@example.org (Bismark Espinoza)
email@example.com (Perry Hutchison)
firstname.lastname@example.org (David St. Pierre)
This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:10:17 CDT