Skip to content

Instantly share code, notes, and snippets.

@gom
Created November 4, 2010 14:25
Show Gist options
  • Save gom/662525 to your computer and use it in GitHub Desktop.
Save gom/662525 to your computer and use it in GitHub Desktop.
gem install net-ssh notify
# -*- coding: utf-8 -*-
require 'rubygems'
require 'net/ssh'
require 'notify'
def daemonize(&block)
if Process.respond_to? :daemon
Process.daemon(&block)
else
require 'WEBrick'
WEBrick::Daemon.start(&block)
end
end
hostname = 'remote_host_name'
user = 'username'
key = '~/.ssh/id_rsa'
path = '/path/to/file.log'
daemonize {
Net::SSH.start(hostname, user, :keys => [key]) do |ssh|
ssh.open_channel do |ch|
ch.on_data do |c,data|
Notify.notify hostname, data
end
ch.exec "tail -f #{path}"
end
ssh.loop
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment