Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'net/ssh'
- require 'net/ssh/proxy/command'
- require 'net/ssh/gateway'
- require 'mysql2'
- require 'active_record'
- proxy = Net::SSH::Proxy::Command.new('ssh hgoe -W %h:%p')
- option = {
- keys: ['~/.ssh/key'],
- proxy: proxy
- }
- gateway = Net::SSH::Gateway.new(
- 'host',
- 'user',
- option
- )
- db_connection = nil
- gateway.open('rdb_host', 3306) do |local_port|
- MarioProd.establish_connection(
- adapter: 'mysql2',
- host: '127.0.0.1',
- port: local_port,
- username: 'username',
- password: 'password',
- database: 'database'
- )
- db_connection = ActiveRecord::Base.connection
- end
- db_connection.execute(sql)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement