115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/webbynode/ssh.rb', line 115
def execute(script, echo=false, ret_exit_code=false)
connect
output = ""
error_output = ""
exit_code = nil
channel = @conn.open_channel do |chan|
chan.on_request('exit-status') do |ch, data|
exit_code = data.read_long
end
chan.on_data do |ch, data|
puts data if echo
output << data
end
chan.on_extended_data do |ch, type, data|
next unless type == 1
puts data if echo
output << data
error_output << data
end
chan.exec("#{script} < /dev/null") do |ch, s|
raise Exceptions::SshInstallationError, "Error executing script \"#{script[:name]}\"" unless s
end
end
channel.wait
return exit_code if ret_exit_code
output
end
|