If you set up a rake task in lib/tasks/your_cron_job.rake with
something like this

namespace :your_cron_job do
   desc "describe the task"
   task :every_five_minutes => :environment do
       @post = Post.new
   end
end

you can add it manually to the cron by typing 'crontab -e' which opens
the file for editing (*nix only)
crontab -e

first specify how often you want the job to run... in this case every
5 minutes "*/5 * * * *" along with correct paths to app and rake, set
the RAILS_ENV and task name to execute. Cron is just a file so you'll
enter all the info for the job on one line like so... (if you don't
have a default editor set up already it will prompt you to do so
before entering in this command).

*/5 * * * * cd /var/www/my_ror_application  && /usr/bin/rake
RAILS_ENV=production your_cron_job:every_five_minutes

More info here 
http://seanbehan.com/programming/set-cron-job-to-run-every-five-minutes-for-a-ruby-on-rails-rake-task/
There are more elegant approaches to this problem. This is just the
quick and dirty.

On Apr 6, 3:32 am, ct9a <[email protected]> wrote:
> hi guys,
>
>  I would like to write a script that is runned by cron. It will update
> multiple entries.
>
>  Any guides for this?
> I can't figure out how do we choose which ruby environment (ie.
> development/test/production) in the script
> and also, how do I access  models in the script (which is also used by
> my rails application)?
>
> thanks

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to