# Script/runner and cron, funny behavior

**URL:** <https://www.ruby-forum.com/t/script-runner-and-cron-funny-behavior/113049>\
**Category:** Rails\
**Created:** [August 26, 2007, 11:14pm UTC](https://www.ruby-forum.com/t/script-runner-and-cron-funny-behavior/113049 "2007-08-26T23:14:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rmac217](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bc8723/32.png) [@rmac217](https://www.ruby-forum.com/u/rmac217)\
**Post date:** [August 26, 2007, 11:14pm UTC](https://www.ruby-forum.com/t/script-runner-and-cron-funny-behavior/113049/1 "2007-08-26T23:14:47Z")

</div>

I couldn’t figure out why my cronjobs weren’t executing correctly. They  
would run, but the code would not be executed. Here’s what the problem  
was:

This was the cronjob that was not working correctly:

- 
  - 
    - 
      - 
        - /path/to/app/script/runner -e production “Code.to\_execute”

And this is what I had to do to get it to work:

- 
  - 
    - 
      - 
        - cd /path/to/app/; ./script/runner -e production  
“Code.to\_execute”

Why does changing into the app’s directory before executing runner make  
a difference? Anyone else run into this before?

---

<div class="post-metadata">

**Author:** ![rmac217](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bc8723/32.png) [@rmac217](https://www.ruby-forum.com/u/rmac217)\
**Post date:** [August 27, 2007, 11:28pm UTC](https://www.ruby-forum.com/t/script-runner-and-cron-funny-behavior/113049/2 "2007-08-27T23:28:33Z")

</div>

> Why does changing into the app’s directory before executing runner make  
> a difference? Anyone else run into this before?

Dunno, but change that cron to this:

cd /path/to/app && ./script/runner…

That way if for some reason it can’t ‘cd’ it won’t try and do the  
‘runner’…

-philip

---

<div class="post-metadata">

**Author:** ![rmac217](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bc8723/32.png) [@rmac217](https://www.ruby-forum.com/u/rmac217)\
**Post date:** [May 8, 2010, 7:29pm UTC](https://www.ruby-forum.com/t/script-runner-and-cron-funny-behavior/113049/3 "2010-05-08T19:29:37Z")

</div>

Ryan M. wrote:

> I couldn’t figure out why my cronjobs weren’t executing correctly. They  
> would run, but the code would not be executed. Here’s what the problem  
> was:
> 
> This was the cronjob that was not working correctly:
> 
> - 
> - 
> - 
> - 
> - /path/to/app/script/runner -e production “Code.to\_execute”
> 
> And this is what I had to do to get it to work:
> 
> - 
> - 
> - 
> - 
> - cd /path/to/app/; ./script/runner -e production  
> “Code.to\_execute”
> 
> Why does changing into the app’s directory before executing runner make  
> a difference? Anyone else run into this before?

Hi Ryan M.  
Thx very much for your answer. I am also facing the same situation  
before reading your post. Now me 2 execute my cron file successfully.

Thank you
