Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Script to setup ssh tunnel to a remote mysql server (See related posts)

#!/usr/bin/env ruby

require 'yaml'
require 'rubygems'
require_gem 'net-ssh'

$stdout.sync = true

def help
  puts <<-USAGE
        This tool allows you to setup an ssh tunnel to a remote mySQL server

  Useage:
    dbssh 
    Please specify configuration in ~/.dbsshrc

  Example:  

    example ~/.dbsshrc:   

      server_name:
        server: servername.com.au
        username: user_id
        password: password_cleartext
        remote_port: 3306
        local_port: 3307
        
  USAGE
  exit
end

app_name = ARGV[0] || help
$config = YAML::load(File.open(File.expand_path("~/.dbsshrc")))[app_name]

puts "connecting to #{$config["server"]}"

exec("ssh -2 -f -c blowfish -N -C #{$config["username"]}@#{$config["server"]} -L #{$config["local_port"]}/127.0.0.1/#{$config["remote_port"]}")

puts ""
puts "success!"


You need to create an account or log in to post comments to this site.


Related Posts