我写了一个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)
我想拦截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) 我想在一个fixtures文件中使用一个对象,该文件在另一个fixture文件中实例化.像下面的东西(这是行不通的):
monitor_france:
objecttype_id: 2
name1: i-france-1
name2: <%= monitors(:big_brother).name %>
Run Code Online (Sandbox Code Playgroud)
如果你想知道我为什么尝试这样奇怪的事情:我正在处理遗留数据库...