Created
January 21, 2011 13:43
-
-
Save dongyuwei/789690 to your computer and use it in GitHub Desktop.
This file contains 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
require 'rubygems' | |
require 'eventmachine' | |
require 'net/ssh' | |
require 'net/scp' | |
require 'ruby-growl' | |
#http://codeforpeople.rubyforge.org/directory_watcher/classes/DirectoryWatcher.html | |
module Handler | |
def file_modified | |
puts "#{path} modified" | |
host = "10.210.74.63" | |
username = "my name" | |
password = "my password" | |
source = "/Users/dyw/test.js" | |
target = "/opt/" | |
recursive = false | |
self.upload(host, username,password,source, target,recursive) | |
end | |
def file_moved | |
puts "#{path} moved" | |
end | |
def file_deleted | |
puts "#{path} deleted" | |
end | |
def unbind | |
puts "#{path} monitoring ceased" | |
end | |
def upload(host, username,password,source, target,recursive) | |
Net::SCP.start(host, username, :password => password) do |scp| | |
scp.upload!(source, target,:recursive => recursive)do |ch, name, sent, total| | |
#progress reports | |
puts "#{name}: #{sent}/#{total}" | |
end | |
g = Growl.new "127.0.0.1", "ruby-growl", ["ruby-growl Notification"] | |
g.notify "ruby-growl Notification", "File monitor", "#{path} modified,synced to server !" | |
end | |
end | |
end | |
EM.kqueue = true if EM.kqueue? # file watching requires kqueue on OSX | |
EM.run { | |
EM.watch_file("/Users/dyw/test.js", Handler) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment