Need assistance to define path on a script which cron will execute

I have written a script to execute some sql statement via executable file.

It is working fine via command line, however when I schedule it in cron.

The executable file is looking for library file in its root directory.

Wonder where does cron run the script from, and can we get the script to get the "jobs" run in a directory that we define. Thanks.

I've tried below and is still failing

* * * * * cd /path/execdir && /path/execdir/script.sh

I even put the path in the script, but still it is not working.

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/o/b/utility/bin

Hi,

I don't think it's problem with path instead some command which is being used in the script. The command path might be available to ur shell but not to from.

Yeah? So how do I get the cron to also use my environment when running using command line as opposed to when it runs in cron.

. /etc/profile ; rest of stuff perhaps.

1 Like

I found the fix, what I did was execute the user's bash_profile in the script or in cron for e.g.

0 10,22 * * * . $HOME/.bash_profile && /root/auto/generate_rpt.bash.

above fixed it for me.

Thanks.

1 Like