Hi,
I've managed to write a simple script in 5 minutes (a bit dirty but it works) for adding the multiple folder watch functionality to transmission-daemon (on linux).
It's using inotify-tools.
Code: Select all
#!/bin/bash
inotifywait -q -r -m $1 --format %w%f -e create |
while read file; do
if echo "$file" | grep -iq "\.torrent" ; then
canonfile=$(readlink -f "$file")
dir=$(dirname "$canonfile")
if echo `basename "$file"` | grep -iq "^\._"; then
echo
else
#echo "Waiting for the file to close"
while : ; do
a=`stat -c%s "$canonfile"`
sleep 0.5s
if [ $a -gt 0 ]; then break; fi
done
while : ; do
a=`stat -c%s "$canonfile"`
sleep 5s
if [ $a -eq `stat -c%s "$canonfile"` ]; then break; fi
done
transmission-remote -a "$canonfile" -w "$dir"
rm -f "$canonfile"
fi
fi
done
As always with watching files from an external process you never know when will it finish writing, given you have no signal from the writing process. So race conditions appears. I've mitigated that by watching file grow until it stops. I'm watching the file first get passed zero because in my experiments sometimes it will stay to zero for a couple of seconds before starting to grow.
No, using close_write event will not do it, for example samba will close and reopen the file multiple times during a transfer..
Note: This part " grep -iq "^\._";" is for filtering out the crap Mac OS X will write on a samba share along with the file you copy.
So basically you'll lunch this script from ex. /etc/rc.local with the parameter of the root folder you want to watch. It will recursively watch all the subfolders from then on for .torrents file. This script can be modified to watch only a specific folder (and ran multiple times with different folders to selectively watch a number of folders) by just modifying the first line "inotifywait -q -r -m $1 --format %w%f -e create |" by removing the "-r" parameter.
Cheers!