1

In terminal i write: ruby lib/scripts/script.rb

In on script.rb I have 2 scripts...

script.rb

    require 'config/environment'

    #first script
#notifier user that question deadline is over and show statistics
inquiry.each do |i|   
    question          = i.question 

    #respondent        = Respondent.find(:all, :conditions => ["id = (?)", i.respondent_id])
    respondent        = i.respondent

    #Notifier.deliver_deadline_notification(inquiry, user, question, respondent)
     Notifier.deliver_statistics_notification(inquiry, question, user, respondent)

    #respondent        = Respondent.find(:all, :conditions => ["id = (?)", i.respondent_id])
    #respondents.each do |r|         
    #end
end

-----------------

    #second script
respondents       = Respondent.find(:all)
inquiries         = Inquiry.find(:all, :conditions => ["is_answered = 0 AND respondent_id = (?)", respondents])
#respondents       = Respondent.find(:first, :conditions => ["id = (?)", inquiries])

questions       = Question.find(:all) 
qdead           = questions.deadline

dead_line_date  = qdead - 1.days - 0.minutes - 0.seconds 
get_time_now    = Time.now.strftime('%m/%d/%Y') 

I have those 2 scripts (1 script do something ,and second is another) in one rb file. My question is... How do I can write in console to launch 1st script and 2nd script simultaneously? I know i use some AGVG ? But How?

Thank you very much!

UPD: using cron i wrote:

0 0 * * * /usr/bin/rails-run-script myproject script oncoming

0 1 * * * /usr/bin/rails-run-script myproject script missed

d

oncoming and missed - arguments. How i can deprecate them in my script.rb. How script will know that Im using missed or oncoming ?

2
  • If your two chunks are in one file, then you only have one script. What do you want to do? ("launch .. simultaneously" -- there's only one script here.) Commented Jul 6, 2011 at 10:58
  • i update my question. I meant if i will use cron, i write this in console how my script (or cron) will be know that im using missed or oncoming? Commented Jul 6, 2011 at 11:11

1 Answer 1

1

If I get your question right, what you have is a script that behaves differently based on the command line argument you pass to the script, right?

So script missed does a and script oncoming does something else.

If it's really just as simple as that, you could simply decide on ARGV.first.

case ARGV.first 
when "oncoming"
  # your "oncoming" logic (preferably wrapped in a method call) here
when "missed"
  # your "missed" logic
else
  $stderr.puts "Call the script with either missed or oncoming" 
  exit 1
end

however, if you want to do anything slightly more complex with options, I'd highly recommend using optparse.rb which is included in rubys stdlib (http://ruby-doc.org/stdlib/libdoc/optparse/rdoc/index.html)

Sign up to request clarification or add additional context in comments.

1 Comment

thank you this is extacly what i need!!!!! I should write exactly ARGV.first ? It is necessary to write , yes?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.