Welcome Guest | Login

Running an action in a Cron job?

Hi,

I want the site send out a weekly email. With PHP this was simply a sending a command through to call the PHP file, but I've tried using

ruby script/runner 'require "open-uri"; open("http://londonprogressivejournal.com/model/action")'

but this doesn't work. How can I alter this to function correctly?

Cheers
Theo

2008-02-14 06:11 PM

http://londonprogressivejournal.com
http://pocuswhiteface.com
Try as below.

cd <yourapp> && script/runner 'require "open-uri"; open("http://londonprogressivejournal.com/model/action")'

2008-02-14 06:42 PM

Hi, thanks a lot but I'm afraid that still didn't work. Here is the error I got from the the cron job:

"/usr/bin/env: ruby: No such file or directory"

My app is in the 'root' directory as I see it when I FTP in, the same level as public_html, which is how the FAQ here tells you to place it, and then spoof public_html to redirecting to the 'public' folder inside. Or something like that...

Cheers
Theo

2008-02-15 03:40 AM

http://londonprogressivejournal.com
http://pocuswhiteface.com
Hi - Could you please try replacing the shebang line (first line)of your script to

#!/usr/local/bin/ruby.

Thank you

2008-02-15 04:13 AM

HostingRails Support
Thank you. Can I just check. You want me to put this:

#!/usr/local/bin/ruby cd <yourapp> && script/runner 'require "open-uri"; open("http://londonprogressivejournal.com/model/action")'

Or

#!/usr/local/bin/ruby script/runner 'require "open-uri"; open("http://londonprogressivejournal.com/model/action")'

Cheers
Theo

2008-02-15 04:31 AM

http://londonprogressivejournal.com
http://pocuswhiteface.com
Hi

Please open the script "script/runner" using vi editor and then change the first line to

#!/usr/local/bin/ruby

then in your crontjob you can add the following

cd /home/username/<yourapp> && script/runner 'require "open-uri";open("http://londonprogressivejournal.com/model/action")'

2008-02-15 05:01 AM

HostingRails Support
Okay, thank you. :-)

2008-02-15 05:02 AM

http://londonprogressivejournal.com
http://pocuswhiteface.com
Hi,

Okay, so this never worked and I gave up. But now I need it to. I did what was suggested above but what I get now is a failure and the following errors:

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:204:in `establish_connection': development database is not configured (ActiveRecord::AdapterNotSpecified)
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:195:in `establish_connection'
from /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/initializer.rb:229:in `initialize_database'
from /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/initializer.rb:88:in `process'
from /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/initializer.rb:43:in `send'
from /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/initializer.rb:43:in `run'
from ./script/../config/../config/environment.rb:13
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
from /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/runner.rb:39
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
from script/runner:3

2008-06-16 01:08 PM

http://londonprogressivejournal.com
http://pocuswhiteface.com
Hi - This is because script/runner by default operates under development mode. You need to specify the environment using the -e option

------------------------------
[~]# script/runner -h
Usage: script/runner [options] ('Some.ruby(code)' or a filename)

   -e, --environment=name           Specifies the environment for the runner to operate under (test/development/production).
------------------------------

So you can just change the cronjob to

cd /home/username/<yourapp> && script/runner --environment=production 'require "open-uri";open("http://londonprogressivejournal.com/model/action")'

2008-06-16 02:09 PM

HostingRails Support
Cheers. I'll see if that works on Friday morning.

Thank you for your help. :-)

2008-06-16 02:57 PM

http://londonprogressivejournal.com
http://pocuswhiteface.com

Hello Guest! In order to post you must be an active client with us, please log in or sign up.