# Require and Cron

**URL:** <https://www.ruby-forum.com/t/require-and-cron/63631>\
**Category:** Ruby\
**Created:** [June 16, 2006, 8:51pm UTC](https://www.ruby-forum.com/t/require-and-cron/63631 "2006-06-16T20:51:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![siguva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@siguva](https://www.ruby-forum.com/u/siguva)\
**Post date:** [June 16, 2006, 8:51pm UTC](https://www.ruby-forum.com/t/require-and-cron/63631/1 "2006-06-16T20:51:11Z")

</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!

---

<div class="post-metadata">

**Author:** ![siguva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@siguva](https://www.ruby-forum.com/u/siguva)\
**Post date:** [June 16, 2006, 9:06pm UTC](https://www.ruby-forum.com/t/require-and-cron/63631/2 "2006-06-16T21:06:02Z")

</div>

On Sat, 17 Jun 2006 03:51:27 +0900  
Hunter W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

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

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

---

<div class="post-metadata">

**Author:** ![siguva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@siguva](https://www.ruby-forum.com/u/siguva)\
**Post date:** [June 16, 2006, 9:34pm UTC](https://www.ruby-forum.com/t/require-and-cron/63631/3 "2006-06-16T21:34:22Z")

</div>

On Jun 16, 2006, at 8:51 PM, Hunter W. 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

---

<div class="post-metadata">

**Author:** ![siguva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@siguva](https://www.ruby-forum.com/u/siguva)\
**Post date:** [June 16, 2006, 11:15pm UTC](https://www.ruby-forum.com/t/require-and-cron/63631/4 "2006-06-16T23:15:15Z")

</div>

Daniel H. wrote:

> On Jun 16, 2006, at 8:51 PM, Hunter W. 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!
