Lenovo U410
root@paardenpad:~# cat /usr/bin/watcher.sh
#!/bin/bash
inotifywait -m -r -e modify,create,delete,move --format '%T %e %w%f' --timefmt '%a %d %b %Y %T %Z' -o /var/log/picturesFileChanges /home/rijk/Documents/Pictures
root@paardenpad:~# cat /lib/systemd/system/watcher.service
[Unit]
Description=Shell Script to Watch Rijks Pictures
[Service]
ExecStart=/usr/bin/watcher.sh
[Install]
WantedBy=multi-user.target
ProBook 6550b (vervangen door versie zonder python)
root@paardenpad:/etc/init.d# aptitude install python-pyinotify
root@paardenpad:/usr/local# mkdir -p scripts
root@paardenpad:/usr/local/scripts/watcher# wget https://raw.githubusercontent.com/splitbrain/Watcher/master/watcher.py
root@paardenpad:/usr/local/scripts/watcher# chmod +x watcher.py
root@paardenpad:/usr/local/scripts/watcher# vim /etc/watcher.ini
; ----------------------
; General Settings
; ----------------------
[DEFAULT]
; where to store output
logfile=/var/log/watcher.log
; where to save the PID file
pidfile=/tmp/watcher.pid
; ----------------------
; Job Setups
; ----------------------
[job1]
; directory or file to watch. Probably should be abs path.
watch=/home/rijk/Documents/Pictures
; list of events to watch for.
; supported events:
; 'access' - File was accessed (read) (*)
; 'attribute_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,delete,modify,move
; Comma separated list of excluded dir. Absolute path needed.
; Leave blank if no excluded dir setted
excluded=
; if true, watcher will monitor directories recursively for changes
recursive=true
; if true, watcher will automatically watch new subdirectory
autoadd=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)
; $cookie event cookie (integer used for matching move_from and move_to events, otherwise 0)
command=echo `date` event=$tflags file=$filename >> /var/log/picturesFileChanges
- Create symlink to create service and enable it
root@paardenpad:/etc/init.d# ln -s /usr/local/watcher/watcher.py watcher
root@paardenpad:/etc/init.d# update-rc.d watcher defaults
root@paardenpad:/etc/init.d# service watcher start