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!"