Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. require 'net/ssh'
  2. require 'net/ssh/proxy/command'
  3. require 'net/ssh/gateway'
  4. require 'mysql2'
  5. require 'active_record'
  6.  
  7. proxy = Net::SSH::Proxy::Command.new('ssh hgoe -W %h:%p')
  8. option = {
  9. keys: ['~/.ssh/key'],
  10. proxy: proxy
  11. }
  12. gateway = Net::SSH::Gateway.new(
  13. 'host',
  14. 'user',
  15. option
  16. )
  17.  
  18. db_connection = nil
  19. gateway.open('rdb_host', 3306) do |local_port|
  20. MarioProd.establish_connection(
  21. adapter: 'mysql2',
  22. host: '127.0.0.1',
  23. port: local_port,
  24. username: 'username',
  25. password: 'password',
  26. database: 'database'
  27. )
  28. db_connection = ActiveRecord::Base.connection
  29. end
  30. db_connection.execute(sql)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement