Hi all,
As context, we're simply trying to remotely (automatically) "su" to a
different user and issue commands as that user, while still being able
to differentiate between stderr and stdout on the subsequent commands.
If there's a common pattern for doing this, then answering my specific
question isn't all that important (to me). Thanks!
So, I'm trying to use Net::SSH to do some remote automation and when we
need to su to do something, thus requiring a pty, it seems that the
on_extended_data doesn't get called on stderr and that it, instead, gets
mashed into on_data:
Example:
- - - - -
require 'rubygems'
require 'net/ssh'
command = "cat slartibartfast"
Net::SSH.start(host, user, :password => password) do |ssh|
channel = ssh.open_channel do |ch|
channel.request_pty do |ch, success|
raise "no pty!" if !success
end
ch.exec command do |ch, success|
raise "could not execute command" unless success
password_sent = false
ch.on_data do |c, data|
puts "stdout: " + data
end
ch.on_extended_data do |c, type, data|
puts "stderr: " + data
end
end
end
channel.wait
end
- - - - -
Output:
- - - - -
stdout: cat: cannot open slartibartfast
stdout:
- - - - -
If I take the request for the pty out, everything behaves as expected.
Is this intentional behavior? I have yet to dig into the source, but
will tomorrow.
Thanks again!
Najati
···
--
Posted via http://www.ruby-forum.com/.