Here is the code:
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
Is there a better way to escape the shell command, preferably in a format that allows sh "ssh root@#{server} #{command}"
to be used with arbitrary command
s?
使用require 'shellwords'
和Shellwords.escape
您可以在“ shellescape ”和“ Shellwords ”中找到有关这些的更多信息。
您可以使用%q
和%Q
版本,但仍需要指定定界符。
%Q|these don't need to be escaped /\"'"'{}[]-_+=()!@#$%^&*`~;:<>.,|
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.