I have done something similar before. You'll need to install the package inotify-tools.
Might need a little tweaking to do exactly as you want probably, but here is a start. You would create a file somewhere in your home folder, put the following into it, mark the file executable, and in the Startups Applications program add the full path to the file to run it at login. It keeps running once started, and creates a log file in your home folder so you can check it is working (remove the echo command to disable logging).
- Code: Select all
#!/bin/bash
# configure logfile
LOGFILE=~/.copied_torrents.log
# configure folder to watch for .torrent files being created
SRCDIR=/home/media/Downloads
# configure folder to move the .torrent files to
DSTDIR=/home/media/.gvfs/torrents\ on\ trotsky
# watch SRCDIR for closed files and move them to DSTDIR if they are .torrent files
do_watch () {
while true; do
NAME=$(inotifywait --quiet --event close --format '%f' "$SRCDIR")
if [[ -f "$SRCDIR/$NAME" && "$NAME" =~ .*\.torrent ]]; then
echo "$(date +'%b %d %X'): moving .torrent file $SRCDIR/$NAME to $DSTDIR" >> "$LOGFILE"
mv "$SRCDIR/$NAME" "$DSTDIR"
fi
done
}
# start watching
do_watch &
If you want to try it out, probably best put a line with "exit" on it after the line "mv $SRCDIR/$NAME $DSTDIR". That way you can start it manually and it will exit after the first file that matches. Else if you want to tweak and test the script some more, you'd have to find all the started processes and kill them.
Edit: some changes because you have folder names with spaces in them and I didn't account for that
