Crontab sourcing PATH?

Hi,

Im trying to run script A which requires path /sbin.
I have a crontab entry to run script A every 10 minutes.
Script A is executed fine by cron, but because script A requires /sbin in its path it fails to run.
My situation is script A get overwritten from time to time so I can't modify script A to set path in there.

So my question is...
Is it possible to execute script A in cron by sourcing the path somehow without setting the path in the script.

I've tried exporting PATH and running the script but it seems like when the script executes, it is running with the default cron PATH.

Is there a cron default file which specifies this limited PATH? I would like to add the path there if it exists. /etc/crontab contains below

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed

It already has /sbin specified, so then why does it only have /usr/bin:/bin in its path when executing?

I'm using RHEL 6.2.

Hope my question is clear.
Thanks.

Wilson.

Okay then set the PATH in your crontab

0, 10,20,30,40,50  * * * *  export PATH=${PATH}:/sbin && /path/to/my/script

Hi Jim,

I tried your suggestion and this is what I get. I have echo $PATH > tmp.file in the script A so I can check if the path has been sourced. It continues to print one with /sbin in its path which I think is being logged from export then once the script A executes it prints the PATH as being /usr/bin:/bin to the default again.

/usr/bin:/bin:/sbin
/usr/bin:/bin

Thanks.

Wilson.

If the contents of the script change the PATH variable and you don't have any permanent control over the contents of the script you have two choices from what I can see:

1) Create symlinks in /usr/bin for the /usr/sbin executables the script needs. This can be a pain if there's a lot of them or if it's a long script and hard to guess what all it does, but it's a definite workaround to your issues with the script.

2) Explain to whoever is in charge of writing the script that it's broken. Ultimately there's only so much you can do if the script is breaking itself. Let them know that the change their script is making is causing it to have a bug on your platform and let them fix it however they need to. It's possible they wrote it for some other platform where all the executables it needs are either in /usr/bin or /bin.

Hi thmnetwork,

I ended up asking the script owner to add the PATH. Thanks for the suggestions.

Wilson.