Created
October 7, 2016 11:02
-
-
Save marcroberts/a80a6160e9afbe29c29bb7db263c0fd2 to your computer and use it in GitHub Desktop.
something for watching files in the current directory
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
| #!/usr/local/bin/ruby | |
| require 'rubygems' | |
| require 'inotify' | |
| i = Inotify.new | |
| last_events = {} | |
| watcher = Thread.new do | |
| i.each_event do |ev| | |
| last_events[ev.name] = Time.now.to_i | |
| end | |
| end | |
| mover = Thread.new do | |
| while true do | |
| now = Time.now.to_i | |
| last_events.each do |k, v| | |
| if ( now - v) > 10 | |
| print "moving #{k}" | |
| last_events.delete k | |
| end | |
| end | |
| sleep 1 | |
| end | |
| end | |
| i.add_watch('.', Inotify::CLOSE_WRITE) | |
| watcher.join | |
| mover.join |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment