[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Problem with cronjob and ruby script

Matthew Lagace

6/5/2009 1:48:00 PM

Hello,

I'm trying to get a ruby script run into a crontab and it keeps failing
saying it can't find my mechanize gem. When I run the script form the
command line, everything runs fine and I don't get any failures.

Anyone ever had that problem before?
--
Posted via http://www.ruby-....

19 Answers

David Rio

6/5/2009 2:26:00 PM

0

On Fri, Jun 5, 2009 at 3:48 PM, Matthew Lagace <mlagace@rasib.ca> wrote:
> Hello,
>
> I'm trying to get a ruby script run into a crontab and it keeps failing
> saying it can't find my mechanize gem. When I run the script form the
> command line, everything runs fine and I don't get any failures.
>
> Anyone ever had that problem before?

Make sure you have this ENV variables pointing to the correct dirs:

GEM_HOME=/usr/local/rubygems/gems
GEM_PATH=/usr/local/rubygems/gems
RUBYLIB=/usr/local/rubygems/lib/ruby/site_ruby/1.8

-drd

eddie

6/5/2009 2:31:00 PM

0

Matthew Lagace <mlagace@rasib.ca> writes:

>Hello,

>I'm trying to get a ruby script run into a crontab and it keeps failing
>saying it can't find my mechanize gem. When I run the script form the
>command line, everything runs fine and I don't get any failures.

Often and often when cron jobs fail it is because the environment variables
are not set. Cron jobs do not automatically execute .bashrc (or equivalent)
you generally need to create a script that calls your program after either
setting the environment by hand or doing eg ". .bashrc".

Eddie

Bil Kleb

6/5/2009 2:43:00 PM

0

Matthew Lagace wrote:
> Hello,

Hi.

> I'm trying to get a ruby script run into a crontab and it keeps failing
> saying it can't find my mechanize gem. When I run the script form the
> command line, everything runs fine and I don't get any failures.
>
> Anyone ever had that problem before?

Oh yes.

Try getting it to run from the command line with a blank
environment with 'env -', e.g.,

% env - run_stuff.sh

Typically a crontab job runs with a much reduced environment.

Alternatively, stick a printenv in your crontab to see
what environment it is working with and compare to your
interactive environment.

You might also find crontab's sister command, 'at', helpful
to get tighter feedback cycles.

Regards,
--
http://twitter.co...

James French

6/5/2009 2:52:00 PM

0

Hi,

If I start by a human-written block of data, such as ITEMS below, is it pos=
sible to deserialize these into objects of type Item? How might this be don=
e?

Thanks for any help,
James


ITEMS =3D %q{
---
item:
- name: blah
- type: blah
- location: blah
}

class Item

attr_accessor :name
attr_accessor :type
attr_accessor :location
=20
def initialize
@name =3D ""
@type =3D ""
@location =3D ""
end
=20
end

Matthew Lagace

6/5/2009 3:01:00 PM

0

Hmm I've tried running with a blank environment and it fails with the
same error not finding the gems. I have set the ENV variables to the
proper directories and it is still giving me the same error. I'm not
sure what else to try although I appreciate all your recommendations!



Bil Kleb wrote:
> Matthew Lagace wrote:
>> Hello,
>
> Hi.
>
>> I'm trying to get a ruby script run into a crontab and it keeps failing
>> saying it can't find my mechanize gem. When I run the script form the
>> command line, everything runs fine and I don't get any failures.
>>
>> Anyone ever had that problem before?
>
> Oh yes.
>
> Try getting it to run from the command line with a blank
> environment with 'env -', e.g.,
>
> % env - run_stuff.sh
>
> Typically a crontab job runs with a much reduced environment.
>
> Alternatively, stick a printenv in your crontab to see
> what environment it is working with and compare to your
> interactive environment.
>
> You might also find crontab's sister command, 'at', helpful
> to get tighter feedback cycles.
>
> Regards,

--
Posted via http://www.ruby-....

Hassan Schroeder

6/5/2009 3:22:00 PM

0

On Fri, Jun 5, 2009 at 8:00 AM, Matthew Lagace<mlagace@rasib.ca> wrote:
> Hmm I've tried running with a blank environment and it fails with the
> same error not finding the gems. I have set the ENV variables to the
> proper directories and it is still giving me the same error.

Set them *where*? You need to set them in your crontab directly,
*not* in your personal e.g. .bashrc.

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

Matthew Lagace

6/5/2009 3:37:00 PM

0

Oh I see can you give me an example please?

Thanks!

Hassan Schroeder wrote:
> On Fri, Jun 5, 2009 at 8:00 AM, Matthew Lagace<mlagace@rasib.ca> wrote:
>> Hmm I've tried running with a blank environment and it fails with the
>> same error not finding the gems. I have set the ENV variables to the
>> proper directories and it is still giving me the same error.
>
> Set them *where*? You need to set them in your crontab directly,
> *not* in your personal e.g. .bashrc.

--
Posted via http://www.ruby-....

cnjohnson

6/5/2009 3:52:00 PM

0


On Jun 5, 2009, at 10:36 AM, Matthew Lagace wrote:

> Oh I see can you give me an example please?
>
> Thanks!
>
You may find this helpful: http://blog.spikesource.com/c...

Cheers--

Charles
---
Charles Johnson
Advanced Computing Center for Research and Education
Vanderbilt University




Kyle Schmitt

6/5/2009 3:56:00 PM

0

On Fri, Jun 5, 2009 at 10:36 AM, Matthew Lagace<mlagace@rasib.ca> wrote:
> Oh I see can you give me an example please?
>
> Thanks!


From (recent) experience here, I've had similar issues across
different versions of the same distro (CentOS/RedHat). The paths and
environment variables are drastically different. For me, I was
shelling out to lspci

Something along the lines of this would have been a valid fix.

#Crontab
0 1 * * * PATH=$PATH:/sbin /usr/bin/ruby /usr/local/bin/nitejob.rb

Hassan Schroeder

6/5/2009 4:14:00 PM

0

On Fri, Jun 5, 2009 at 8:36 AM, Matthew Lagace<mlagace@rasib.ca> wrote:
> Oh I see can you give me an example please?

Sure, here's one:

5,20,35,50 * * * * export JAVA_HOME=/usr/local/jdk1.6_013 &&
/usr/bin/jruby - S blah blah

HTH,
--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com