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

**URL:** <https://community.unix.com/t/need-assistance-to-define-path-on-a-script-which-cron-will-execute/372435>\
**Category:** Shell Programming and Scripting\
**Created:** [May 23, 2018, 1:08pm UTC](https://community.unix.com/t/need-assistance-to-define-path-on-a-script-which-cron-will-execute/372435 "2018-05-23T13:08:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaapar](https://community.unix.com/letter_avatar/jaapar/32/6_449c533f586939b6e5f246632a46421f.png) [@jaapar](https://community.unix.com/u/jaapar)\
**Post date:** [May 23, 2018, 1:08pm UTC](https://community.unix.com/t/need-assistance-to-define-path-on-a-script-which-cron-will-execute/372435/1 "2018-05-23T13:08:51Z")

</div>

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

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

```

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

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

```

---

<div class="post-metadata">

**Author:** ![panyam](https://community.unix.com/letter_avatar/panyam/32/6_449c533f586939b6e5f246632a46421f.png) [@panyam](https://community.unix.com/u/panyam)\
**Post date:** [May 23, 2018, 1:34pm UTC](https://community.unix.com/t/need-assistance-to-define-path-on-a-script-which-cron-will-execute/372435/2 "2018-05-23T13:34:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jaapar](https://community.unix.com/letter_avatar/jaapar/32/6_449c533f586939b6e5f246632a46421f.png) [@jaapar](https://community.unix.com/u/jaapar)\
**Post date:** [May 23, 2018, 1:59pm UTC](https://community.unix.com/t/need-assistance-to-define-path-on-a-script-which-cron-will-execute/372435/3 "2018-05-23T13:59:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/6_449c533f586939b6e5f246632a46421f.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [May 23, 2018, 2:06pm UTC](https://community.unix.com/t/need-assistance-to-define-path-on-a-script-which-cron-will-execute/372435/4 "2018-05-23T14:06:59Z")

</div>

`. /etc/profile ; rest of stuff` perhaps.

---

<div class="post-metadata">

**Author:** ![jaapar](https://community.unix.com/letter_avatar/jaapar/32/6_449c533f586939b6e5f246632a46421f.png) [@jaapar](https://community.unix.com/u/jaapar)\
**Post date:** [May 23, 2018, 2:07pm UTC](https://community.unix.com/t/need-assistance-to-define-path-on-a-script-which-cron-will-execute/372435/5 "2018-05-23T14:07:01Z")

</div>

> [@jaapar](#):
>
> 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.

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

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

```

above fixed it for me.

Thanks.
