[sllug-members]: cron job environment

Stuart Jansen sjansen at buscaluz.org
Fri Aug 4 12:49:58 MDT 2006


On Fri, 2006-08-04 at 12:34 -0600, Shaun Kruger wrote:
> Is your script sensitive about the current working directory?

In my experience, you should never rely on the current working directory
when launching a cron job. Instead, provide the full path to the script.
If on script needs to call other scripts, it should contain something
like:
cd "$(dirname $0)"
near the beginning of the script and then use relative paths to refer to
the rest of the scripts.

> If in your crontab file you manually enter your PATH= so it matches
> your user's path you should be able to get the correct behavior.

It is rarely a good idea to duplicate information. If the goal is to
duplicate the shell environment of a user, just start a login shell as I
demonstrated using bash -l.

-- 
Stuart Jansen              e-mail/jabber: sjansen at buscaluz.org
                           google talk:   stuart.jansen at gmail.com

"However beautiful the strategy, you should occasionally look at 
the results." -- Winston Churchill
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://sllug.org/pipermail/sllug-members/attachments/20060804/7cae64b5/attachment.pgp


More information about the sllug-members mailing list