【发布时间】:2015-02-03 19:37:32
【问题描述】:
代码如下:
desc "Find 301 errors on production servers"
task :find301 do
command = "grep 'HTTP/1.1\" 301' /var/log/httpd/*ssl-access.log | grep -v 'gclid' | awk '{print \$7}' | sort | uniq -c | sort -nr"
production_servers.each do |server|
sh "ssh root@#{server} #{command}"
end
end
有没有更好的方法来转义 shell 命令,最好是允许sh "ssh root@#{server} #{command}" 与任意commands 一起使用的格式?
【问题讨论】: