Report abuse

Instructions

Put this in /home/deploy/bin/shell 
chmod +x it
command="/home/deploy/bin/shell" ssh-dss AAAAB3Nza........

in /home/deploy/.ssh/authorized_keys

Script

#!/usr/bin/env ruby

require 'logger'

LAUNCH_TIME = Time.now
SHELL_NAME = "deploy-shell/%.5f-%06d" % [LAUNCH_TIME.to_f, $$]
LOGGER = Logger.new("/tmp/#{SHELL_NAME}.log")
#LOGGER.progname = SHELL_NAME

begin
##################

require 'pp'
require 'stringio'

class Object
  def to_pp
    old_stdout = $stdout
    $stdout = StringIO.open("", "w")
    pp self
    $stdout.string
  ensure
    $stdout = old_stdout
  end
end

LOGGER.debug "Starting at #{Time.now}"
LOGGER.debug "Running #{ENV["SSH_ORIGINAL_COMMAND"]}"
LOGGER.debug "ARGV: \n#{ARGV.to_pp}"
LOGGER.debug "ENV: \n#{ENV.to_pp}"

system(ENV["SSH_ORIGINAL_COMMAND"])

LOGGER.debug "Stopping at #{Time.now}"

##################
rescue Object => e
  LOGGER.error "Error: #{e.class}: #{e.message}"
  abort "Failed!"
end

# vim:sts=2:ts=2:sw=2:et:filetype=ruby