# Require and Cron

**URL:** <https://rubytalk.org/t/require-and-cron/28255>\
**Category:** ruby-talk\
**Created:** [16 June 2006 18:51 UTC](https://rubytalk.org/t/require-and-cron/28255 "2006-06-16T18:51:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hunter](https://avatars.discourse-cdn.com/v4/letter/h/ba9def/32.png) [@Hunter](https://rubytalk.org/u/Hunter)\
**Post date:** [16 June 2006 18:51 UTC](https://rubytalk.org/t/require-and-cron/28255/1 "2006-06-16T18:51:27Z")

</div>

I have another ruby file that is required to run my app.

require 'QuickBaseClient' #this points to the QuickBaseClient.rb in the  
same directory as the file I am running.

When I run this script from the command line: ruby init.rb it works  
great.

When Cron tries to run it, it balks at the fact that it can't find  
QuickBaseClient

I imagine Cron is running this script in a temp dir, so I guess I need  
to point at the original location of the QuickBaseClient.rb? If so, how  
do I do that in code. I've always just used: require 'QuickBaseClient'  
and Ruby has found the file and used its methods.

Thanks for your help!

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Steve\_D](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@Steve\_D](https://rubytalk.org/u/Steve_D)\
**Post date:** [16 June 2006 19:03 UTC](https://rubytalk.org/t/require-and-cron/28255/2 "2006-06-16T19:03:18Z")

</div>

You can create a bash script and execute that. Something like:

#!/bin/bash  
cd /home/dir/to/app  
ruby init.rb

> **···**
>
> On Sat, 17 Jun 2006 03:51:27 +0900 Hunter Walker \<walkerhunter@gmail.com\> wrote:
> 
> > I have another ruby file that is required to run my app.
> > 
> > require 'QuickBaseClient' #this points to the QuickBaseClient.rb in the  
> > same directory as the file I am running.
> > 
> > When I run this script from the command line: ruby init.rb it works  
> > great.
> > 
> > When Cron tries to run it, it balks at the fact that it can't find  
> > QuickBaseClient
> > 
> > I imagine Cron is running this script in a temp dir, so I guess I need  
> > to point at the original location of the QuickBaseClient.rb? If so, how  
> > do I do that in code. I've always just used: require 'QuickBaseClient'  
> > and Ruby has found the file and used its methods.
> > 
> > Thanks for your help!
> > 
> > --  
> > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Daniel\_Harple](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@Daniel\_Harple](https://rubytalk.org/u/Daniel_Harple)\
**Post date:** [16 June 2006 19:32 UTC](https://rubytalk.org/t/require-and-cron/28255/3 "2006-06-16T19:32:34Z")

</div>

The file can not be found in any directory in $LOAD\_PATH when cron runs the ruby process. It works when you run init.rb from the same directory because "." is in the $LOAD\_PATH. Try:

require File.dirname(\_\_FILE\_\_) + "/QuickBaseClient" # \_\_FILE\_\_ is the current source file

Another tip -- files are usually named like this: quick\_base\_client.rb

-- Daniel

> **···**
>
> On Jun 16, 2006, at 8:51 PM, Hunter Walker wrote:
> 
> > require 'QuickBaseClient' #this points to the QuickBaseClient.rb in the  
> > same directory as the file I am running.
> > 
> > When I run this script from the command line: ruby init.rb it works  
> > great.
> > 
> > When Cron tries to run it, it balks at the fact that it can't find  
> > QuickBaseClient

---

<div class="post-metadata">

**Author:** ![Hunter](https://avatars.discourse-cdn.com/v4/letter/h/ba9def/32.png) [@Hunter](https://rubytalk.org/u/Hunter)\
**Post date:** [16 June 2006 21:15 UTC](https://rubytalk.org/t/require-and-cron/28255/4 "2006-06-16T21:15:29Z")

</div>

Daniel Harple wrote:

> **···**
>
> > On Jun 16, 2006, at 8:51 PM, Hunter Walker wrote:
> > 
> > > require 'QuickBaseClient' #this points to the QuickBaseClient.rb  
> > > in the  
> > > same directory as the file I am running.
> > > 
> > > When I run this script from the command line: ruby init.rb it works  
> > > great.
> > > 
> > > When Cron tries to run it, it balks at the fact that it can't find  
> > > QuickBaseClient
> > 
> > The file can not be found in any directory in $LOAD\_PATH when cron  
> > runs the ruby process. It works when you run init.rb from the same  
> > directory because "." is in the $LOAD\_PATH. Try:
> > 
> > require File.dirname(\_\_FILE\_\_) + "/QuickBaseClient" # \_\_FILE\_\_ is the  
> > current source file
> > 
> > Another tip -- files are usually named like this: quick\_base\_client.rb
> > 
> > -- Daniel
> 
> Hi Daniel,
> 
> Thank you for the response. I am a little confused. When you mean the  
> source file, is that the QuickBaseClient.rb that is located in the same  
> folder as my init.rb? Also, should the file name be in quotes? Thank  
> you for your help!
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
