Skip to content

Instantly share code, notes, and snippets.

@anthonybishopric
Created June 12, 2014 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anthonybishopric/84b12d1e1832acdf15d2 to your computer and use it in GitHub Desktop.
Save anthonybishopric/84b12d1e1832acdf15d2 to your computer and use it in GitHub Desktop.
Shush
#!/usr/bin/env ruby
require 'optparse'
options = {source: File.expand_path("~/.profile-remote"), target: "~/.profile"}
OptionParser.new do |opts|
opts.banner = "Copy a .profile script to a machine for sshing to it.\nUsage: shush [options] host"
opts.on("-s", "--source SOURCE", "The source profile file. Default is ~/.profile-remote") do |s|
options[:source] = File.expand_path(s)
end
opts.on("-t", "--target TARGET", "The target profile file. Default is ~/.profile on the remote machine") do |t|
options[:target] = t
end
end.parse!
abort("#{options[:source]} does not exist") unless File.exist?(options[:source])
host = ARGV[0]
abort "You must specify a host" unless host
cmd = "scp #{options[:source]} #{host}:#{options[:target]}"
puts cmd
`#{cmd}`
abort "Could not copy file to target host" unless $?.success?
exec("ssh #{host}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment