I’ve been working on a script that is to be run from a couple different locations/servers (all checked out from svn). To get the script’s directory (used for generating files in the directory), I have been using this:
script_dir="$( cd "$( dirname "$0" )" && pwd )"
This works great, but does not seem to execute in crontab. I have made sure that there are no relative paths used in the script, and this script works through crontab when substituting $script_dir with the directory’s path.
Any thoughts?
dirnameis probably not in the default PATH for cron jobs. I don’t know about your system, but on OS X dirname is in /usr/bin, which isn’t in cron’s default PATH. If this is the problem, there are 3 easy ways to fix this:script_dir="$( cd "$( /usr/bin/dirname "$0" )" && pwd )"PATH=/usr/bin:/bin:/usr/sbin:/sbin(or something like that)PATH=/usr/bin:/bin:/usr/sbin:/sbin(make sure this line is before the entry that runs your script)