Created
November 4, 2010 14:25
-
-
Save gom/662525 to your computer and use it in GitHub Desktop.
gem install net-ssh notify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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