Skip to content

Instantly share code, notes, and snippets.

@SwathiMystery
Last active December 16, 2015 05:59
Show Gist options
  • Save SwathiMystery/5388835 to your computer and use it in GitHub Desktop.
Save SwathiMystery/5388835 to your computer and use it in GitHub Desktop.
Using watcher.py for real time of s3 uploads
$ cd Watcher/
Start the script,
$ sudo python watcher.py start
This will create a .watcher dirctory at /home/ubuntu
Now,
$ sudo python watcher.py stop
Goto the .watcher directory created and
set the destination to be watched for and action to be undertaken
in jobs.yml ie. watch: and command:
# Copyright (c) 2010 Greggory Hernandez
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# ---------------------------END COPYRIGHT--------------------------------------
# This is a sample jobs file. Yours should go in ~/.watcher/jobs.yml
# if you run watcher.py start, this file and folder will be created
job1:
# a generic label for a job. Currently not used make it whatever you want
label: Watch /home/ubuntu/data for added or removed files
# directory or file to watch. Probably should be abs path.
watch: /home/ubuntu/data
# list of events to watch for.
# supported events:
# 'access' - File was accessed (read) (*)
# 'atrribute_change' - Metadata changed (permissions, timestamps, extended attributes, etc.) (*)
# 'write_close' - File opened for writing was closed (*)
# 'nowrite_close' - File not opened for writing was closed (*)
# 'create' - File/directory created in watched directory (*)
# 'delete' - File/directory deleted from watched directory (*)
# 'self_delete' - Watched file/directory was itself deleted
# 'modify' - File was modified (*)
# 'self_move' - Watched file/directory was itself moved
# 'move_from' - File moved out of watched directory (*)
# 'move_to' - File moved into watched directory (*)
# 'open' - File was opened (*)
# 'all' - Any of the above events are fired
# 'move' - A combination of 'move_from' and 'move_to'
# 'close' - A combination of 'write_close' and 'nowrite_close'
#
# When monitoring a directory, the events marked with an asterisk (*) above
# can occur for files in the directory, in which case the name field in the
# returned event data identifies the name of the file within the directory.
events: ['create', 'move_from', 'move_to']
# TODO:
# this currently isn't implemented, but this is where support will be added for:
# IN_DONT_FOLLOW, IN_ONESHOT, IN_ONLYDIR and IN_NO_LOOP
# There will be further documentation on these once they are implmented
options: []
# if true, watcher will monitor directories recursively for changes
recursive: true
# the command to run. Can be any command. It's run as whatever user started watcher.
# The following wildards may be used inside command specification:
# $$ dollar sign
# $watched watched filesystem path (see above)
# $filename event-related file name
# $tflags event flags (textually)
# $nflags event flags (numerically)
# $dest_file this will manage recursion better if included as the dest (especially when copying or similar)
# if $dest_file was left out of the command below, Watcher won't properly
# handle newly created directories when watching recursively. It's fine
# to leave out when recursive is false or you won't be creating new
# directories.
# $src_path is only used in move_to and is the corresponding path from move_from
# $src_rel_path [needs doc]
command: sudo sh /home/ubuntu/s3sync/monitor.sh $filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment