cron not always executing scripts with the

I am experiencing a problem with cron that has just cropped up. I have been installing scripts on various networked machines using various approved standard user accounts. Up until recently, these scripts (just 1 or 2 lines) have been working fine. The scripts simply start a Perl script and pass in an argument. I have been installing these shells as the applicable users in the same way for over a year without any problems. Lately, the scripts are failing because, when they run, they are not running with the user's runtime environment. Note that the scripts all work fine when I run them as the user from the command line. Most of the OS versions are 5.8, with a few of the older machines running 5.6 (due to the inability to upgrade Sybase). Some of the user accounts have /bin/sh as their login shells, some use /bin/csh and others use /bin/ksh (my personal favorite). To work around this problem, we have been setting the applicable environment variables in the shells that are failing (or, running the appropriate .?shrc file). So, what is causing cron to not run the scripts with the user's environment?

[1122 byte] By [harleyChuckGa] at [2007-11-26 15:51:08]
# 1

hi,

when we get this kind of problem, since we're always in a hurry and don't have any time to investigate this kind of issues, we usually use this in our crontab (ksh related)

42 07 * * 1-5/bin/ksh -c '. $HOME/.profile; /$HOME/p3milan/bin/startp3v5 debugapi' > /tmp/$USER.startp3.out 2>&1

obviously this is one of our example, you have to customize it according to your environment

and I'm quite sure we have had simiar problems with the csh as well and we have solved it in the same way (sourcing .cshrc of course)

tittaa at 2007-7-8 22:11:09 > top of Java-index,General,Sys Admin Best Practices...
# 2
I've found an example of a user using the CSHhere it is18 22 * * 1-5 /bin/csh -c 'source $HOME/.cshrc; /home/glcs/cs/tomcat/bin/shutdown.sh' > /tmp/stopsm.log 2>&1and it does work
tittaa at 2007-7-8 22:11:09 > top of Java-index,General,Sys Admin Best Practices...
# 3

> So, what is causing cron to not run the

> scripts with the user's environment?

Solaris cron has *never* provided a user's environment.

# man crontab

[...]

The shell is invoked from your $HOME directory with an arg0

of sh. Users who desire to have their .profile executed must

explicitly do so in the crontab file. cron supplies a

default environment for every shell, defining HOME, LOGNAME,

SHELL(=/bin/sh), TZ, and PATH. The default PATH for user

cron jobs is /usr/bin; while root cron jobs default to

/usr/sbin:/usr/bin. The default PATH canbesetin

/etc/default/cron; see cron(1M).

[...]

I have no idea why your problem just cropped up, but it shouldn't be because cron was providing a user environment in the past.

--

Darren

Darren_Dunhama at 2007-7-8 22:11:09 > top of Java-index,General,Sys Admin Best Practices...