【问题标题】:Error 32512 running a system call from Ruby script run from crontab从 crontab 运行的 Ruby 脚本运行系统调用时出现错误 32512
【发布时间】:2011-06-24 20:09:51
【问题描述】:

我在从用户的 crontab 运行 Ruby 脚本时遇到问题。当您以该用户身份从终端运行它时,它可以正常工作。从 crontab 运行时,系统调用失败。

这是脚本;

#!/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 

当由 crontab 运行时会产生此日志;

    # 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

命令 runWatir 是一个 bash shell 脚本,位于 wca 目录中。

#!/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

我的菜鸟错误是什么?

【问题讨论】:

    标签: ruby linux cron


    【解决方案1】:

    cron 作业以具有不同环境变量集的不同用户身份运行。您的PATHrvm 设置等将不可用,除非您手动设置它们。我猜你会被其中之一击中。要尝试的事情是确保 cron 作业和常规 shell 中的 ruby​​ 版本相同,用户相同且路径相同。

    【讨论】:

    • 从命令行,用 sudo 运行它,看看它从 cron 运行时可能会发生什么。
    • 好吧,sudo -u <user>。并非所有 cron 作业都以 root 身份运行。
    猜你喜欢
    • 2016-12-18
    • 2023-03-21
    • 2021-06-27
    • 1970-01-01
    • 2017-03-28
    • 1970-01-01
    • 1970-01-01
    • 2013-12-20
    • 2017-02-05
    相关资源
    最近更新 更多