Skip to content

Instantly share code, notes, and snippets.

@russss
Created January 19, 2011 12:34
Show Gist options
  • Save russss/786112 to your computer and use it in GitHub Desktop.
Save russss/786112 to your computer and use it in GitHub Desktop.
Mirror new files in a directory to another machine
# usage: python mirrordir.py ./directory myuser@host:/path
import sys, pyinotify, subprocess
class Handler(pyinotify.ProcessEvent):
def process_IN_CLOSE_WRITE(self, event):
subprocess.call(("scp", event.pathname, sys.argv[2]))
if __name__ == '__main__':
wm = pyinotify.WatchManager()
notifier = pyinotify.Notifier(wm, default_proc_fun=Handler())
wm.add_watch(sys.argv[1], pyinotify.IN_CLOSE_WRITE, rec=True, auto_add=True)
notifier.loop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment