I’m trying to setup a simple timer that gets started from a Rails Application. This timer should wait out its duration and then start a shell script that will start up ./script/runner and complete the initial request. I need script/runner because I need access to ActiveRecord.
Here’s my test lines in Rails
output = `at #{(Time.now + 60).strftime("%H:%M")} < #{Rails.root}/lib/parking_timer.sh STRING_VARIABLE`
return render :text => output
Then my parking_timer.sh looks like this
#!/bin/sh
~/PATH_TO_APP/script/runner -e development ~/PATH_TO_APP/lib/ParkingTimer.rb $1
echo "All Done"
Finally, ParkingTimer.rb reads the passed variable with
ARGV.each do|a|
puts "Argument: #{a}"
end
The problem is that the Unix command “at” doesn’t seem to like variables and only wants to deal with filenames. I either get one of two errors depending on how I position “s
If I put quotes around the right hand side like so
… “~/PATH_TO_APP/lib/parking_timer.sh STRING_VARIABLE”
I get,
-bash: ~/PATH_TO_APP/lib/parking_timer.sh STRING_VARIABLE: No such file or directory
I I leave the quotes out, I get,
at: garbled time
This is all happening on a Mac OS 10.6 box running Rails 2.3 & Ruby 1.8.6
I’ve already messed around w/ BackgrounDrb, and decided its a total PITA. I need to be able to cancel the job at any time before it is due.
After playing around with
irba bit, here’s what I found.The backtick operator invokes the shell after ruby has done any interpretation necessary. For my test case, the
straceoutput looked something like this:Since we know what it’s doing, let’s take a look at how your command will be executed:
That looks very odd. Do you really want to pipe
parking_timer.sh, the script, as input into theatcommand?What you probably ultimately want is something like this:
Thus, the output of the
parking_timer.shcommand will become the input to theatcommand.So, try the following:
You can always use
straceortrussto see what’s happening. For example:Then
grep '^exec' strace.out*to see where the command is being executed.