Having problems running shell script from crontab
kayasaman at gmail.com
Sat Jan 7 14:43:35 UTC 2012
On 01/07/2012 04:30 PM, Matthew Seaman wrote:
> On 07/01/2012 13:57, RW wrote:
>> On Sat, 07 Jan 2012 15:37:49 +0200
>> Kaya Saman wrote:
>> n terms of paths this is what I'm doing: I'm in a FreeBSD jail
>>> logged in by - #jexec<jail> tcsh
>>> which gets me in as root. Crontab is being run as root so paths
>>> should be the same no?
> No -- you can't assume that. The correct thing to do is to set $PATH
> within your script, then it should stand a much improved chance of
> running correctly irrespective of how it gets started. Add a line like
> this near the top of the script:
> export PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
> That should be good enough for most purposes, but feel free to modify if
> Another debugging tip: add
> set -x
> set -v -x
> towards the top of the script and you'll get a trace of what the script
> does e-mailed to you. (Well, e-mailed to root, but I assume yould've
> been reading root's mailbox anyhow, or redirected the root e-mails to
> somewhere more useful.)
>> PATH is set at the top of /etc/crontab
> Well, yes. However that only helps for the scripts run out of
> /etc/crontab. If the OP has done the right thing and left /etc/crontab
> alone, but instead set up a root crontab by running
> # crontab -u root -e
> then that wouldn't help at all.
Thanks Matthew!!! :-)
Exporting the PATH variable was the key, although I did add the
debugging tip in for good measure.
So luckily all is solved now.
Thanks everyone for all the help and advice!
More information about the freebsd-questions