Version 7 (modified by Waldorf, 12 years ago) (diff) |
---|
Watch Directory Script
Notes
To run this script at an interval, add this to your crontab.
Script "watchdog.sh"
#!/bin/bash # Watch dir, may contain spaces: watchdir="/torrentwatch/" # move file to a subdirectory? if Commented out, it'll removed remove # the torrent file. # Note: Don't put a '/' before the path! movesubdir="added/" # Authentication "username:password": #tr_auth="admin:admin" # Transmission host: tr_host="127.0.0.1:9091" # Verbose? verbose=1 ############################################# time=$(date "+%Y-%m-%d (%H:%M:%S)") if [ -n "$tr_auth" ]; then tr_auth="--auth=$tr_auth" fi for file in "$watchdir"*.torrent do if [ -f "$file" ]; then if [ -n "$verbose" ]; then echo "$time: $file added to queue."; fi /usr/local/bin/transmission-remote "$tr_host" "$tr_auth" -a "$file" > /dev/null # give the remote some time to process sleep 5 if [ $movesubdir ]; then if [ -d "$watchdir$movesubdir" ]; then mv "$file" "$watchDir$movesubdir" else mkdir "$watchdir$movesubdir" mv "$file" "$watchdir$movesubdir" fi else rm "$file" fi else if [ -n "$verbose" ]; then echo "$time: No torrent in $watchdir."; fi fi done exit 0