Sha256: a30d25f8ca08efc705d48ffd6d848fd83e0aaa6a7cd1f4a4e5d0f43f03ad64c6
Contents?: true
Size: 1.82 KB
Versions: 9
Compression:
Stored size: 1.82 KB
Contents
#!/usr/bin/env ruby require 'fileutils' include FileUtils::Verbose require 'tins/go' include Tins::GO =begin ~/.ssh/config: Host * ForwardX11 = yes ControlMaster auto ControlPath ~/.ssh/%r@%h:%p.sock =end def usage puts <<EOT Usage: #{File.basename($0)} [OPTS] [user@]remote[:port]" OPTS is one of -N list all session names on the specified remote -n NAME name of the screen session to attach to (defaults to $USER) -t [TUNNEL_HOST[:TUNNEL_PORT]] host:port to tunnel if different from LOCALPORT -l LOCALPORT the localport to forward to if different from TUNNEL_PORT -h to display this help EOT exit 1 end arguments = ARGV.dup opts = go 'l:t:n:hN', arguments usage if opts['h'] || arguments.size != 1 user_remote = arguments.shift user, remote, rport = case user_remote when /\A(?:([^@:]+)@)?([^@:]+)(?::(\d+))?\Z/ user = $1 || ENV['USER'] user.to_s.empty? and fail "user required to login" [ user, $2, $3 || '22' ] else usage end lport = opts['l'] tunnel, tport = nil, nil if tunnel_port = opts['t'] case tunnel_port when /\A([^:]+)(?::(\d+))?\Z/ tunnel, tport = $1, $2 || '22' lport ||= tport else usage end else tunnel, tport = 'localhost', lport end ssh_dir = File.expand_path('~/.ssh') mkdir_p ssh_dir sock_file = "#{ssh_dir}/#{user}@#{remote}:#{rport}.sock" env_user = ENV['USER'] and opts['n'] ||= env_user if opts['N'] exec "ssh -p #{rport} -S #{sock_file} #{user}@#{remote} screen -ls" elsif lport rm_f sock_file exec "ssh -p #{rport} -Mt -L localhost:#{lport}:#{tunnel}:#{tport}"\ " -S #{sock_file} #{user}@#{remote} screen -DUR #{opts['n']}" else rm_f sock_file exec "ssh -p #{rport} -Mt -S #{sock_file} #{user}@#{remote} screen -DUR #{opts['n']}" end
Version data entries
9 entries across 9 versions & 1 rubygems