Error 32512 running a system call from Ruby script run from crontab
I am having a problem getting a Ruby script to work correctly when run from a user's crontab. It works okay when you run it from the terminal as that user. When run from crontab it fails on a system call.
Here is the script;
#!/usr/bin/ruby
require "net/http"
require "logger"
require "pp"
begin
Dir.chdir("wca")
time1 = Time.new
filename = "updated" + "_" + time1.hour.to_s + "_" + time1.min.to_s + "_" + time1.sec.to_s + ".log"
log = Logger.new(filename)
log.debug "===Checking For New Build"
source = Net::HTTP.get('yr-qa-svr2', '/Wave/index.html')
myFile = File.new("data/old.html","rb")
old = myFile.read
myFile.close
if old != source then
log.debug " Server Version Changed, running tests"
status = system("runWatir","webdriver.rb")
if status then
log.debug " Command run correctly"
myFile = File.new("data/old.html","w")
myFile.puts source
myFile.close
else
log.debug " Failed to run command"
log.debug " Error number " + $?.to_s
end
else
log.debug " No Updates to Server Version"
end
rescue Exception => e
print "Exception occured: " + e + "\n"
print e.backtrace
end
When run from by crontab is produces this log;
# Logfile created on Fri Jun 24 02:00:01 +0100 2011 by logger.rb/22285
D, [2011-06-24T02:00:01.333921 #4409] DEBUG -- : ===Checking For New Build
D, [2011-06-24T02:00:01.433632 #4409] DEBUG -- : Server Version Changed, running tests
D, [2011-06-24T02:00:01.462700 #4409] DEBUG -- : Failed to run command
D, [2011-06-24T02:00:01.462919 #4409] DEBUG -- : Error number 32512
The command runWatir is a bash shell script located in the wca directory.
#!/bin/bash
rm logs开发者_如何转开发/*.log
rm logs/*.png
export DATE=`date`
ruby -W0 $1|tee logs/$1.log
export RESULT=`grep assertions logs/$1.log`
export TIMED=`grep Finished logs/$1.log`
export BUILD=`cat logs/build.log`
ruby library/GenEmailMsg.rb "WATIR Results for $DATE" "Attached are the results from the WATIR automated test [$1] run with $BUILD..The results are $RESULT..$TIMED" logs/$1.log
What is my rookie mistake?
cron
jobs run as a different user with a different set of environment variables. Your PATH
, rvm
settings etc. will not be available unless you manually set them. I'm guessing you're getting hit by one of these. The things to try are to make sure that your ruby version is the same in the cron job and your regular shell, that the users are the same and that the paths are the same.
精彩评论