I'm not sure if this should be asked on ServerFault or here as it's a server problem that's specific to Mechanize and Nokogiri in a Rails 3.2.3 application.
I have a rake task that scrapes a Latitude and Longitude from one of our service providers websites.
I have set the task up in 'crontab -e' along with the other tasks. For some reason, on two supposidly idential servers, one the the servers fails to complete the rake task with the following error:
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
Message-Id: <20120410134631.2CFA624B76@localhost>
Date: Tue, 10 Apr 2012 14:46:30 +0100 (BST)
rake aborted!
/var/www/railsapp/lib/tasks/peoplesafelocation.rake:29: undefined (?...) sequence: /new GLatLng\(\s*(?<lat>.+?)\s*,\s*(?<long>.+?)\s*\)/
Both servers are running Rails 3.2.3, Ruby 1.9.2.
I can't understand why it would fail with 'undefined (?...) sequence' on one server but not the other.
Both servers are using RVM and are running Ubuntu 10.04.
The full rake task is as follows:
desc "Import Peoplesafe Location"
task :fetch_peoplesafelocation => :environment do
# Logs into provider.co.uk/live and retrieved latitude and longitude.
require 'rubygems'
require 'mechanize'
require 'logger'
require 'nokogiri'
# Create a new mechanize object
agent = Mechanize.new
# Load the Peoplesafe website
page = agent.get("http://provider.co.uk/live/")
# Select the first form
form = agent.page.forms.first
form.username = 'User'
form.password = 'Password'
# Submit the form
page = form.submit form.buttons.first
page = agent.get("http://provider.co.uk/live/?gps&cid=AAXA-PJZM6M")
html_doc = page.root
script = page.at('/html/head/script[not(@src)]')
parts = script.text.match(/new GLatLng\(\s*(?<lat>.+?)\s*,\s*(?<long>.+?)\s*\)/)
#puts parts[:lat], parts[:long]
Location.create(:latitude => parts[:lat], :longitude => parts[:long])
puts 'Location Updated'
end
Any pointers would be appreciated!