On Oct 10, 2005, at 10:26 AM, hack0r / gmail.com wrote:

> why does this script continue looping and not end gracefully with the
> output I want. I can't figure out where to put channel.close :-(
>
> #!/usr/local/bin/ruby
>
> require 'rubygems'
> require 'net/ssh'
> require "cgi"
>
> def do_tail( session, file )
>   session.open_channel do |channel|
>     channel.on_data do |ch, data|
>       puts "[#{file}] -> #{data}"
>     end
>     channel.exec "tail -f #{file}"
>   end
> end
>
> session = Net::SSH.start( 'servername', 'username', 'password' ) do
> |session|
>   do_tail session, "/var/log/messages"
>   session.loop
> end

   session.loop  
{ some_condition_that_should_return_true_while_work_is_being_done }

See the last paragraph of http://net-ssh.rubyforge.org/ 
chapter-3.html#s2. Basically, session.loop accepts an optional block  
that should return true as long as the loop should continue.

Normally, the loop continues while all channels are open, but in your  
case, a tail -f will never close by itself.

- Jamis