Class: Sprout::SSHTask
- Inherits:
-
Rake::Task
- Object
- Rake::Task
- Sprout::SSHTask
- Defined in:
- lib/sprout/tasks/ssh_task.rb
Overview
The SSHTask allows you to execute arbitrary commands on a remote host.
ssh :update_gem_index do |t|
t.host = 'dev.projectsprouts.com'
t.username = 'someUser'
t.commands << 'cd /var/www/projectsprouts/current/gems'
t.commands << 'gem generate_index -d .'
end
Instance Attribute Summary collapse
-
#commands ⇒ Object
Array of commands that will be executed on the remote machine.
-
#host ⇒ Object
Host name of the server to connect to with no protocol prefix, like: sub.yourhost.com.
-
#password ⇒ Object
Password to send to the remote host.
-
#username ⇒ Object
Username to send to the remote host.
Class Method Summary collapse
Instance Method Summary collapse
-
#execute(*args) ⇒ Object
:nodoc:.
-
#initialize(task_name, app) ⇒ SSHTask
constructor
A new instance of SSHTask.
Constructor Details
#initialize(task_name, app) ⇒ SSHTask
Returns a new instance of SSHTask.
66 67 68 69 70 71 72 |
# File 'lib/sprout/tasks/ssh_task.rb', line 66 def initialize(task_name, app) super(task_name, app) @name = name @host = nil @queue = [] @commands = [] end |
Instance Attribute Details
#commands ⇒ Object
Array of commands that will be executed on the remote machine
57 58 59 |
# File 'lib/sprout/tasks/ssh_task.rb', line 57 def commands @commands end |
#host ⇒ Object
Host name of the server to connect to with no protocol prefix, like: sub.yourhost.com
55 56 57 |
# File 'lib/sprout/tasks/ssh_task.rb', line 55 def host @host end |
#password ⇒ Object
Password to send to the remote host. You will be prompted for this value if it is left null.
NOTE: You should never check a file into version control with this field filled in, it is provided here as a convenience for getting set up.
64 65 66 |
# File 'lib/sprout/tasks/ssh_task.rb', line 64 def password @password end |
#username ⇒ Object
Username to send to the remote host. You will be prompted for this value if it is left null.
59 60 61 |
# File 'lib/sprout/tasks/ssh_task.rb', line 59 def username @username end |
Class Method Details
.define_task(args) {|t| ... } ⇒ Object
:nodoc:
74 75 76 77 |
# File 'lib/sprout/tasks/ssh_task.rb', line 74 def self.define_task(args, &block) # :nodoc: t = super yield t if block_given? end |
Instance Method Details
#execute(*args) ⇒ Object
:nodoc:
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/sprout/tasks/ssh_task.rb', line 79 def execute(*args) # :nodoc: if(@host.nil?) throw SSHError.new('SSH requires a valid host parameter') end if(@username.nil?) print "Username: " @username = $stdin.gets.chomp! raise SFTPError.new('SFTP requires username parameter') unless @username end if(@password.nil?) print "Password: " @password = $stdin.gets.chomp! # @password = Password.get raise SFTPError.new('SFTP requires password parameter') unless @password end puts ">> Connecting to Remote Server: #{@username}@#{@host}:#{@remote_path}" Net::SSH.start(@host, @username, @password) do |session| session.open_channel do |channel| commands.each do |command| puts ">> #{command}" channel.exec command end channel.close end session.loop end end |