shijiang1130 发表于 2013-06-24 19:19

ruby 批量执行命令

Ruby很多很酷的gem。下面我们来看一个CapistranoC:\>cap shell
* 2013-06-24 19:18:08 executing `shell'
====================================================================
Welcome to the interactive Capistrano shell! This is an experimental
feature, and is liable to change in future releases. Type 'help' for
a summary of how to use the shell.
--------------------------------------------------------------------
cap> on 127.0.0.1 localhost 192.168.1.1 ruby -v

shijiang1130 发表于 2013-06-24 19:22

看下官方的capfile:curse:# an esay way to connect to all instances
# cap shell

set :user, ENV['USER']
ssh_options[:keys] = "~/.ssh/id_rsa"
set :use_sudo, false

raise "USAGE: source ./config/FOLDER/settings.sh && cap fooo" unless ENV['SG_NAME']

instances = `as-describe-auto-scaling-groups $SG_NAME --region $REGION|grep ^INSTANCE`.split("\n")
ids = instances.map{|i| i.split(" ")}

instance_info = `ec2-describe-instances #{ids.join(" ")} --region $REGION|grep ^INSTANCE`
addresses = instance_info.map{|i| i.split(" ")}

#puts "addresses: #{addresses.inspect}"
addresses.each do |address|
role :app, "#{address}:22"
end

# example to get current queue from haproxy
task :current_queue do
run "curl 'http://username:password@localhost/haproxy?stats;csv' 2> /dev/null| grep self | awk '{split($0,a,\",\"); print a}'"
end

rubyish 发表于 2013-06-25 14:52

看看我觉得很酷 :lol
页: [1]
查看完整版本: ruby 批量执行命令