[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Crobjob problem with ruby script.

andreas.cahen@gmail.com

3/18/2005 2:24:00 PM

Hi!

Hopefully this is the right place to post my problem.. any help is
appreciated!

I am using two Ruby scripts on my *inux server to purge old records out
of a mysql database. These two scripts run, or should, as cronjobs. If
I start those scripts directly from the shell it all works fine. But as
a cronjob I get the following error:

/backups/scripts/delete_old.rb:1:in `require': No such file to load --
dbi (LoadError)
from /backups/scripts/delete_old.rb:1

The command for the cron job is: ruby /backups/scripts/delete_old.rb

Where did I go wrong? :) Are there any environement variables which I
forgot to set?

Thanks!!

-Andreas

18 Answers

James Britt

3/18/2005 2:59:00 PM

0

andreas.cahen@gmail.com wrote:
> Hi!
>
> Hopefully this is the right place to post my problem.. any help is
> appreciated!
>
> I am using two Ruby scripts on my *inux server to purge old records out
> of a mysql database. These two scripts run, or should, as cronjobs. If
> I start those scripts directly from the shell it all works fine. But as
> a cronjob I get the following error:
>
> /backups/scripts/delete_old.rb:1:in `require': No such file to load --
> dbi (LoadError)
> from /backups/scripts/delete_old.rb:1
>
> The command for the cron job is: ruby /backups/scripts/delete_old.rb
>
> Where did I go wrong? :) Are there any environement variables which I
> forgot to set?

What shebang line are you using?

What user account is executing the code?


>
> Thanks!!
>
> -Andreas
>
>
> .
>

James Britt
--


http://www.ru...
http://www.r...
http://catapult.rub...
http://orbjson.rub...
http://www.jame...


andreas.cahen@gmail.com

3/18/2005 3:55:00 PM

0

James Britt wrote:
>
> What shebang line are you using?
None... do I need to add one to my ruby scripts?

> What user account is executing the code?
root is executing the scripts

-andreas

Robert Klemme

3/18/2005 4:14:00 PM

0


<andreas.cahen@gmail.com> schrieb im Newsbeitrag
news:1111161279.684304.8420@f14g2000cwb.googlegroups.com...
> James Britt wrote:
> >
> > What shebang line are you using?
> None... do I need to add one to my ruby scripts?
>
> > What user account is executing the code?
> root is executing the scripts
>
> -andreas

You probably should set $LOAD_PATH explicitely in the script. Try
ruby -e 'p $LOAD_PATH'
and see what it prints from the command line and from cron.

Kind regards

robert

James Britt

3/18/2005 5:35:00 PM

0

Robert Klemme wrote:
> <andreas.cahen@gmail.com> schrieb im Newsbeitrag
> news:1111161279.684304.8420@f14g2000cwb.googlegroups.com...
>
>>James Britt wrote:
>>
>>>What shebang line are you using?
>>
>>None... do I need to add one to my ruby scripts?
>>
>>
>>>What user account is executing the code?
>>
>>root is executing the scripts
>>
>>-andreas
>
>
> You probably should set $LOAD_PATH explicitely in the script. Try
> ruby -e 'p $LOAD_PATH'
> and see what it prints from the command line and from cron.

I've has issues with cron jobs because of assorted mismatched
user/path/env details.

For example, I tried code that began with #!/usr/bin/env ruby
and this failed because that relies on a given environment setting.

So, perhaps set a shebang line that points right to ruby.
Also, make sure that the $LOAD_PATH is not relying on any special
environment settings (though I've net seen this as an issue myself).

I believe I've had issues with cron job code making false assumptions
about the current directory and relative paths.

Robert's suggestion is a really good one. Ive also done that with a
script to loop over ENV just to see what the whole environment was.

And are you *sure* these need to run as root? One side-effect I have
seen as a result of root cron jobs is that I get files I cannot edit or
delete without becoming root myself.

James Britt



andreas.cahen@gmail.com

3/18/2005 5:56:00 PM

0


Robert Klemme wrote:
>
> You probably should set $LOAD_PATH explicitely in the script. Try
> ruby -e 'p $LOAD_PATH'
> and see what it prints from the command line and from cron.
>

Shell: 375 Bytes
Cron: 159 Bytes

I get a huge difference between executing this command on the shell and
as cronjob.. how comes?

How do I set the $LOAD_PATH? I tried to set it inside my ruby script
but I summoned an error..

Cheers,

-Andreas

Shad Sterling

3/18/2005 6:31:00 PM

0

On Sat, 19 Mar 2005 02:59:52 +0900, andreas.cahen@gmail.com
<andreas.cahen@gmail.com> wrote:
>
> Robert Klemme wrote:
> >
> > You probably should set $LOAD_PATH explicitely in the script. Try
> > ruby -e 'p $LOAD_PATH'
> > and see what it prints from the command line and from cron.
> >
>
> Shell: 375 Bytes
> Cron: 159 Bytes
>
> I get a huge difference between executing this command on the shell and
> as cronjob.. how comes?
>
> How do I set the $LOAD_PATH? I tried to set it inside my ruby script
> but I summoned an error..
>
> Cheers,
>
> -Andreas
>
>



I've had problems with paths in cronjobs even just running shell
scripts. What I recall mostly is that the current directory was
something useless, and "~" was not the home directory. I made
everything work by using all absolute pathes. I don't think that
would be desirable for a require statement, but I expect it would make
it work.

(I don't actually know how require finds the files; I'm guessing
that's what $LOAD_PATH is for?)

- Shad






--

----------

Please do not send personal (non-list-related) mail to this address.
Personal mail should be sent to polyergic@sterfish.com.


Aredridel

3/18/2005 6:51:00 PM

0

> I've had problems with paths in cronjobs even just running shell
> scripts. What I recall mostly is that the current directory was
> something useless, and "~" was not the home directory. I made
> everything work by using all absolute pathes. I don't think that
> would be desirable for a require statement, but I expect it would make
> it work.

As have I. I am routinely annoyed by the lack of environment
initialization under most cron daemons.

> (I don't actually know how require finds the files; I'm guessing
> that's what $LOAD_PATH is for?)

Yeah, or its shorthand $:

Thankfully that's not in the process environment.


Shad Sterling

3/18/2005 7:35:00 PM

0

On Sat, 19 Mar 2005 03:51:04 +0900, Aredridel <aredridel@gmail.com> wrote:
> > I've had problems with paths in cronjobs even just running shell
> > scripts. What I recall mostly is that the current directory was
> > something useless, and "~" was not the home directory. I made
> > everything work by using all absolute pathes. I don't think that
> > would be desirable for a require statement, but I expect it would make
> > it work.
>
> As have I. I am routinely annoyed by the lack of environment
> initialization under most cron daemons.
>


Most cron daemons? Is there one that doesn't have that problem?


- Shad



> > (I don't actually know how require finds the files; I'm guessing
> > that's what $LOAD_PATH is for?)
>
> Yeah, or its shorthand $:
>
> Thankfully that's not in the process environment.
>
>


--

----------

Please do not send personal (non-list-related) mail to this address.
Personal mail should be sent to polyergic@sterfish.com.


Jostein Berntsen

3/18/2005 11:01:00 PM

0

On 18.03.05,23:24, andreas.cahen@gmail.com wrote:
> Hi!
>
> Hopefully this is the right place to post my problem.. any help is
> appreciated!
>
> I am using two Ruby scripts on my *inux server to purge old records out
> of a mysql database. These two scripts run, or should, as cronjobs. If
> I start those scripts directly from the shell it all works fine. But as
> a cronjob I get the following error:
>
> /backups/scripts/delete_old.rb:1:in `require': No such file to load --
> dbi (LoadError)
> from /backups/scripts/delete_old.rb:1
>
> The command for the cron job is: ruby /backups/scripts/delete_old.rb
>
> Where did I go wrong? :) Are there any environement variables which I
> forgot to set?
>

Try this instead in the crontab file:

/usr/bin/ruby /backups/scripts/delete_old.rb

crontab wants the full path to the ruby executable.


- Jostein


--
Jostein Berntsen <jostein.berntsen@sensewave.com>


andreas.cahen@gmail.com

3/19/2005 8:32:00 AM

0

Hi..

I tried it like that but it didn't work :/

Oh my gosh... ruby is powerful but tricky :)

-Andreas

Jostein Berntsen wrote:
>
> Try this instead in the crontab file:
>
> /usr/bin/ruby /backups/scripts/delete_old.rb
>
> crontab wants the full path to the ruby executable.
>