Created
June 12, 2014 18:35
-
-
Save anthonybishopric/84b12d1e1832acdf15d2 to your computer and use it in GitHub Desktop.
Shush
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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