Sha256: 37e9ad8cd11212ad0b1ddb72dab97f57edfb718224c311f4ec0cd9680e799991

Contents?: true

Size: 1.65 KB

Versions: 19

Compression:

Stored size: 1.65 KB

Contents

#!/usr/bin/env ruby

require 'fileutils'
include FileUtils::Verbose
require 'spruz/go'
include Spruz::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
  -t [HOST[:PORT]]    host:port to tunnel if different from LOCALPORT
  -l LOCALPORT        the localport to forward to
  -h                  to display this help

EOT
  exit 1
end

arguments = ARGV.dup
opts = go 'l:t:n:hN', arguments
usage if opts['h'] or 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 = if tunnel_port = opts['t']
  case tunnel_port
  when /\A([^:]+)(?::(\d+))?\Z/
    [ $1, $2 || '22' ]
  else
    usage
  end
else
  [ 'localhost', lport ]
end
ssh_dir = File.expand_path('~/.ssh')
mkdir_p ssh_dir
sock_file = "#{ssh_dir}/#{user}@#{remote}:#{rport}.sock"
if opts['N']
  exec "ssh -p #{rport} -S #{sock_file} #{user}@#{remote} screen -ls"
elsif lport
  File.exist? sock_file and rm_f sock_file
  exec "ssh -p #{rport} -Mt -L localhost:#{lport}:#{tunnel}:#{tport}"\
    " -S #{sock_file} #{user}@#{remote} screen -DUR #{opts['n']}"
else
  File.exist? sock_file and rm_f sock_file
  exec "ssh -p #{rport} -Mt -S #{sock_file} #{user}@#{remote} screen -DUR #{opts['n']}"
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
utils-0.0.21 bin/sshscreen
utils-0.0.20 bin/sshscreen
utils-0.0.19 bin/sshscreen
utils-0.0.18 bin/sshscreen
utils-0.0.17 bin/sshscreen
utils-0.0.16 bin/sshscreen
utils-0.0.15 bin/sshscreen
utils-0.0.14 bin/sshscreen
utils-0.0.13 bin/sshscreen
utils-0.0.12 bin/sshscreen
utils-0.0.10 bin/sshscreen
utils-0.0.8 bin/sshscreen
utils-0.0.7 bin/sshscreen
utils-0.0.6 bin/sshscreen
utils-0.0.5 bin/sshscreen
utils-0.0.4 bin/sshscreen
utils-0.0.3 bin/sshscreen
utils-0.0.2 bin/sshscreen
utils-0.0.0 bin/sshscreen