Ruby批量执行Linux安装程序和脚本

require 'find'
  
module Find   
 def match(*paths)   
   matched = []   
    find(*paths) { |path| matched << path if yield path }   
   return matched   
  end  
 module_function :match  
end

 def ExecuteAllSh(sourcefile)
  sourcefile .each do |s| 
  system("bash \""<< s << "\"")
  end
 end 

 def ExecuteAllPl(sourcefile)
  sourcefile .each do |s| 
  system("perl \""<< s << "\"")
  end
 end

 def ExecuteAllRb(sourcefile)
  sourcefile .each do |s| 
  system("ruby \""<< s << "\"")
  end
 end 

 def ExecuteAllPy(sourcefile)
  sourcefile .each do |s| 
  system("python \""<< s << "\"")
  end
 end

 def ExecuteAllRpmBinRun(sourcefile)
  sourcefile .each do |s| 
  system("\""<< s << "\"")
  end
 end 

 def ExecuteAllClass(sourcefile)
  sourcefile .each do |s| 
  system("java \""<< s[0...-6] << "\"")
  end
 end 

 def ExecuteAllBundle(sourcefile)
  sourcefile .each do |s| 
  system("\""<< s << "\"")
  end
 end 

 def ExecuteAllJar(sourcefile)
  sourcefile .each do |s| 
  system("java -jar \""<< s << "\"")
  end
 end 

ExecuteAllSh Find.match("./"){ |p| ext = p[-3...p.size]; ext && ext.downcase == ".sh"}
ExecuteAllPl Find.match("./"){ |p| ext = p[-3...p.size]; ext && ext.downcase == ".pl"}
ExecuteAllRb Find.match("./"){ |p| ext = p[-3...p.size]; ext && ext.downcase == ".rb"}
ExecuteAllPy Find.match("./"){ |p| ext = p[-3...p.size]; ext && ext.downcase == ".py"}
ExecuteAllRpmBinRun Find.match("./"){ |p| ext = p[-4...p.size]; ext && (ext.downcase == ".rpm" || ext.downcase == ".bin" || ext.downcase == ".run")}
ExecuteAllClass Find.match("./"){ |p| ext = p[-6...p.size]; ext && ext.downcase == ".class"}
ExecuteAllBundle Find.match("./"){ |p| ext = p[-7...p.size]; ext && ext.downcase == ".bundle"}
ExecuteAllJar Find.match("./"){ |p| ext = p[-4...p.size]; ext && ext.downcase == ".jar"}

编程技巧