代码如下:
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}"
与任意 命令一起使用的格式
是什么?
最佳答案
使用 require 'shellwords'
和 Shellwords.escape
您可以在“shellescape”和“Shellwords”中找到有关这些内容的更多信息
关于ruby - 在 Ruby 中正确转义 shell 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28307289/