Created
July 18, 2011 23:37
-
-
Save prodis/1090960 to your computer and use it in GitHub Desktop.
Ruby Fundamental - Exemplos de scripts em Ruby (parte II)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: utf-8 | |
# listar_contatos.rb | |
raise ArgumentError, "=> Quantidade de argumentos incorreta. Exemplo de uso: ruby listar_contatos.rb root minhasenha" if ARGV.size != 2 | |
mysql_user, mysql_pass = ARGV | |
def criar_array(resultado) | |
resultado.split("\n").drop(1) | |
end | |
resultado = `mysql -u#{mysql_user} -p#{mysql_pass} information_schema -e "SELECT schema_name FROM schemata WHERE schema_name LIKE 'fundamental_%' ORDER BY schema_name"` | |
criar_array(resultado).each do |base| | |
resultado = `mysql -u#{mysql_user} -p#{mysql_pass} #{base} -e "SELECT email FROM contatos ORDER BY email"` | |
puts "#{base.gsub('fundamental_', '')} #{criar_array(resultado).join(', ')}" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
raise ArgumentError, "=> Quantidade de argumentos incorreta. Exemplo de uso: ruby listar_contatos.rb root minhasenha" if ARGV.size != 2 | |
mysql_user, mysql_pass = ARGV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resultado = `mysql -u#{mysql_user} -p#{mysql_pass} information_schema -e "SELECT schema_name FROM schemata WHERE schema_name LIKE 'fundamental_%' ORDER BY schema_name"` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
schema_name | |
fundamental_alporo | |
fundamental_prodis | |
fundamental_zeus12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bases = resultado.split("\n").drop(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bases.each do |base| | |
resultado = `mysql -u#{mysql_user} -p#{mysql_pass} #{base} -e "SELECT email FROM contatos ORDER BY email"` | |
emails = resultado.split("\n").drop(1) | |
puts "#{base.gsub('fundamental_', '')} #{emails.join(', ')}" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alporo contato@alporo.com.br | |
homero contato.rj@homeroempresa.com.br, contato.sp@zeusempresa.com.br | |
prodis prodis@gmail.com, prodis@timedev.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bases = resultado.split("\n").drop(1) | |
emails = resultado.split("\n").drop(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def criar_array(resultado) | |
resultado.split("\n").drop(1) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment