小编ela*_*ity的帖子

用于检查运行进程的Bash脚本

我写了一个bash脚本来检查进程是否正在运行.它不起作用,因为ps命令总是返回退出代码1.当我从命令行运行ps命令时,$?是正确设置,但在脚本中它总是1.任何想法?

#!/bin/bash
SERVICE=$1

ps -a | grep -v grep | grep $1 > /dev/null
result=$?
echo "exit code: ${result}"
if [ "${result}" -eq "0" ] ; then
    echo "`date`: $SERVICE service running, everything is fine"
else
    echo "`date`: $SERVICE is not running"
fi
Run Code Online (Sandbox Code Playgroud)

Bash版本:GNU bash,版本3.2.25(1)-release(x86_64-redhat-linux-gnu)

bash

54
推荐指数
7
解决办法
20万
查看次数

Ruby方法拦截

我想拦截ruby类上的方法调用,并且能够在实际执行方法之前和之后执行某些操作.我尝试了以下代码,但得到错误:

MethodInterception.rb:16:in before_filter': (eval):2:inalias_method':undefined方法 say_hello' for classHomeWork'(NameError)from(eval):2:in`after_filter'

任何人都可以帮我做对吗?

class MethodInterception

  def self.before_filter(method)
    puts "before filter called"
    method = method.to_s
    eval_string = "
      alias_method :old_#{method}, :#{method}

      def #{method}(*args)
        puts 'going to call former method'
        old_#{method}(*args)
        puts 'former method called'
      end
    "
    puts "going to call #{eval_string}"
    eval(eval_string)
    puts "return"
  end
end

class HomeWork < MethodInterception
  before_filter(:say_hello)

  def say_hello
    puts "say hello"
  end

end
Run Code Online (Sandbox Code Playgroud)

ruby introspection

5
推荐指数
2
解决办法
2368
查看次数

在另一个夹具文件中使用rails fixture对象

我想在一个fixtures文件中使用一个对象,该文件在另一个fixture文件中实例化.像下面的东西(这是行不通的):

monitor_france:
  objecttype_id: 2
  name1: i-france-1
  name2: <%= monitors(:big_brother).name %>
Run Code Online (Sandbox Code Playgroud)

如果你想知道我为什么尝试这样奇怪的事情:我正在处理遗留数据库...

ruby-on-rails fixtures

1
推荐指数
1
解决办法
1563
查看次数

标签 统计

bash ×1

fixtures ×1

introspection ×1

ruby ×1

ruby-on-rails ×1