I'm trying to make a inotifywait
script take different actions for files vs folders if it sees a close_write flag being raised in the watched directory, but cannot seem to get the checks working.
In other scripts I use these kinds of checks all the time and they just_work, but there seems to be something about inotifywait
I'm not grasping yet.
This is the script in its current form:
#!/bin/bash
dir1=/sambashares
while true; do
inotifywait -r -e close_write "$dir1" | while read f; do
#debug
echo $f
#Is it a directory?
if [[ -d "${f}" ]]; then
#debug
echo "New directory called ${f} detected"
chown -R jake:jake $f
chmod -R 775 $f
cp -R $f /media/lacie/Film
fi
#Is it a file?
if [[ -f "${f}" ]]; then
#debug
echo "New file called ${f} detected"
chown jake:jake $f
chmod 775 $f
cp $f /media/lacie/Film
fi
done
done
If I run this in a terminal to see what is happening all I get is the confirmation a close_write was detected, followed by a "setting up watches" without any other messages or any of the other code being triggered, not even the debug echo directly below:
while read f; do
:-(
I'm running this on Ubuntu server 12.04 LTS 64 bit.
$ bash --version
GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu)
$ dpkg -l | grep inotify
ii inotify-tools 3.13-3
ii libinotifytools0 3.13-3
ii python-pyinotify 0.9.2-1
$ python --version
Python 2.7.3