我想要實現的是一個capistrano3任務,它在所有服務器上執行日誌文件grep - 這將節省大量時間,因爲我們有一個很多服務器都是這樣做的,所以手動或者甚至是腳本化的,但是會依次耗時。當執行的命令沒有返回任何內容時sshkit捕獲是否可能不會返回
我有一個粗糙的邊緣任務實際上工作,除非其中一個服務器沒有返回任何grep。在這種情況下,整個命令都會結束。
因此想知道是否有辦法設置capture
接受空回報。
namespace :admin do
task :log_grep, :command, :file do |t,args|
command = args[:command] || 'ask for a command'
file = args[:file] || 'log_grep_results'
outs = {}
on roles(:app), in: :parallel do
outs[host.hostname] = capture(:zgrep, "#{command}")
end
File.open(file, 'w') do |fh|
outs.each do |host,out|
fh.write(out)
end
end
end
end
這救了我的一天。 – sahil 2016-11-23 08:22:33