I decided to modify my dns-323 scripts to keep my media organized.

Instead of monitoring /incoming for torrents, these scripts monitor /media/movies, /media/mp3 and /media/tv.  when .torrent files are detected, they download to the appropriate /media subdirectory.  transmission stops when the files are downloaded, and any rars are unpacked.

edit 4-dec-08: I think there’s a bug with the unpacker script on rar files with spaces in them.  I don’t have time to fix it, so if you have issues you can just rename your rar files accordingly to weed out the spaces.  :)

If you want to use these scripts, make sure you have created the following directories:

  1. /mnt/HD_a2/logs
  2. /mnt/HD_a2/media
  3. /mnt/HD_a2/media/movies
  4. /mnt/HD_a2/media/mp3
  5. /mnt/HD_a2/media/tv

Also note the locations the actual scripts reside in:

  • torrentwatchdog.sh and unpacker.sh reside in/mnt/HD_a2/ffp/var/scripts
  • editcron.sh resides in /mnt/HD_a2/ffp/start/

You can download these new scripts here.

sorry that the blockquote tags in my blog strip out the spacing … and you may have issues with doublequotes if you are copying and pasting from the blog, so keep an eye on that …

/mnt/HD_a2/ffp/var/scripts/torrentwatchdog.sh:

 #!/bin/sh
###########################################################################
# —[ torrentwatchdog.sh ]—
# script to monitor a selection of directories for new .torrent files.
# if found, queue them up in transmission
# and when done downloading, pause the torrent
# w 10/20/08 horto
# u 10/29/08 horto - implmented “make transmission stop after seeding 1:1″
# u 10/29/08 horto - v2.0, do away with /torrents and /incoming dirs, and
#                    just monitor /media/movies, /media/TV and /media/mp3
#                    directories for torrents so I don’t have to manually
#                    organize everything later!
# u 11/06/08 horto - fixed bug with awk not being found via cron
###########################################################################
TORRENTDIRS=”/mnt/HD_a2/media/movies /mnt/HD_a2/media/tv /mnt/HD_a2/media/mp3″
LOG=/mnt/HD_a2/logs/torrentwd.log
TRANSMISSION_REMOTE=/ffp/bin/transmission-remote

# check each incoming TORRENTDIR for new .torrents
for DIR in $TORRENTDIRS; do
for FILE in $DIR/*.torrent; do

# set download dir to current working dir
$TRANSMISSION_REMOTE -w $DIR
# pick out .torrent files and queue them up
if [ “$FILE” != “$DIR/*.torrent” ]; then
echo [`date`] “$FILE” added to queue. >> $LOG
$TRANSMISSION_REMOTE -a “$FILE”
rm “$FILE”
echo [`date`] “$FILE” deleted. >> $LOG
sleep 1
fi
done
done

# stop completed downloads
for i in `/ffp/bin/transmission-remote -l | grep Done | grep -v Ratio | /ffp/bin/awk ‘{print $1}’”`; do
echo [`date`] stopping torrent id $i >> $LOG
$TRANSMISSION_REMOTE -t $i -S
done

exit 0

/mnt/HD_a2/ffp/var/scripts/unpacker.sh:

#!/bin/sh
##############################################################################
# —[ unpacker.sh ] —
# script to look for rar files inside a specific directory.
# if found, unrar them
# w 10/29/08 horto
##############################################################################
DLDIR=/mnt/HD_a2/media
LOG=/mnt/HD_a2/logs/unpack.log
UNRAR=/ffp/bin/unrar

# quick and dirty check to make sure no active downloads.
# because we don’t want to unrar/delete files that may be actively downloading!
if [ `/ffp/bin/transmission-remote -l | wc -l` -gt 1 ]; then
# stop, because a download is active.
exit 0

else
# continue; because there are no active downloads.
# check incoming DLDIR
for FILE in `find $DLDIR -name “*.rar”`; do
if [ “$FILE” != “*.rar” ]; then
# shell-fu to extract to path containing the rar
FILENAME=`expr //$FILE : ‘.*/\(.*\)’`
UNPACKDIR=`echo $FILE | sed -e s/$FILENAME//g`
echo [`date`] Extracting “$FILE” … >> $LOG

# unrar file to the directory its sitting in
$UNRAR x -y “$FILE” “$UNPACKDIR” >> /dev/null 2>&1
echo [`date`]   … done extracting. >> $LOG

# cleanup - remove the rar file(s)
# note: match .rar, .r01, .r02 … etc
echo [`date`] Removing “$FILENAME and rar files.” >> $LOG
for j in `find $UNPACKDIR -name “*.r??”`; do
rm $j
done
fi
done

exit 0
fi

/mnt/HD_a2/ffp/start/editcron.sh:

 #!/bin/sh
##############################################################################
# —-[ editcron.sh ]—-
# script to keep cronjobs persistent (e.g. after reboot)
# NOTE:  put this in /mnt/HD_a2/ffp/start/ and make it executable.
# w 22/10/08 horto
# ref/credit: http://tinyurl.com/5m2349 - thanks chumby!
#############################################################################
FFP=/mnt/HD_a2/ffp
CRONTXT=$FFP/etc/crontab.txt

# start with existing crontab
# note:  on a fresh reboot, this will always have been reset to standard
/bin/crontab -l > $CRONTXT

# add cronjobs here preceeded by /bin/echo.
# don’t forget to enclose them in double quotes.
/bin/echo “0 * * * * /ffp/var/scripts/torrentwatchdog.sh >> /mnt/HD_a2/logs/torrentwd.log 2>&1″ >> $CRONTXT
/bin/echo “30 3 * * * /ffp/var/scripts/unpacker.sh >> /mnt/HD_a2/logs/unpack.log 2>&1″ >> $CRONTXT

# install the new crontab
/bin/crontab $CRONTXT

# clean up
/bin/rm $CRONTXT

the old v1.0 scripts are available here for reference.  (from this article)


25 Comments to “updated dns-323 bt download management scripts”  

  1. 1 G_E_M_S

    Hello,

    Thanks for this great Howto, i did everything exactly as you describe with some little changes, and it’s working great!!! Thanks alot.

    I’d like the downloaded files to be named as the torrent files, any ideas how to make it?

  2. 2 G_E_M_S

    or even better to start the download into a folder with the name of the torrent file.

    for example, the torrent file is matrix. the download will start into the folder /media/movies/matrix

  3. 3 dave

    Thanks for the scripts, I’ve been using it for a while now. Would it be possible to alter the end of the script for checking if the torrent is done to stop it when the seeding is at 1.0 instead for when the download part is done? I tried doing this myself but my coding skills just where not enough. Thanks for publicizing this for us!

  4. 4 InfernoX

    Hi,
    Must say, fantastic scripts!
    I have a problem though…. …It adds the torrent to download, but removes it at the exact same second from queue.. ..it looks like:
    [Mon Nov 17 00:24:10 GMT 2008] /mnt/HD_a2/Torrents/Torrent-url/Movies/thenameofthe.torrent added to queue.
    [Mon Nov 17 00:24:10 GMT 2008] /mnt/HD_a2/Torrents/Torrent-url/Movies/thenameofthe.torrent deleted.
    [Mon Nov 17 00:24:11 GMT 2008] /mnt/HD_a2/Torrents/Torrent-url/Movies/thenameofthe2.torrent added to queue.
    [Mon Nov 17 00:24:11 GMT 2008] /mnt/HD_a2/Torrents/Torrent-url/Movies/thenameofthe2.torrent deleted.

    thats what the torrentwd.log says.

    What have I done wrong, my torrentwatcher script looks as follows:

    TORRENTDIRS=”/mnt/HD_a2/Torrents/Torrent-url /mnt/HD_a2/Torrents/Torrent-url/TV-series /mnt/HD_a2/Torrents/Torrent-url/Movies”
    LOG=/mnt/HD_a2/logs/torrentwd.log
    TRANSMISSION_REMOTE=/ffp/bin/transmission-remote -n username:password

    # check each incoming TORRENTDIR for new .torrents
    for DIR in $TORRENTDIRS; do
    for FILE in $DIR/*.torrent; do

    # set download dir to current working dir
    $TRANSMISSION_REMOTE -w $DIR

    # pick out .torrent files and queue them up
    if [ “$FILE” != “$DIR/*.torrent” ]; then
    echo [`date`] “$FILE” added to queue. >> $LOG
    $TRANSMISSION_REMOTE -a “$FILE”
    rm “$FILE”
    echo [`date`] “$FILE” deleted. >> $LOG
    sleep 1
    fi
    done
    done

    # stop completed downloads
    for i in `/ffp/bin/transmission-remote -l | grep Done | grep Seeding | grep -v Ratio | /ffp/bin/awk ‘{print $1}’”`; do
    echo [`date`] stopping torrent id $i >> $LOG
    $TRANSMISSION_REMOTE -t $i -S
    done

    exit 0

  5. 5 Pete

    Hi,

    I can’t edit the files inside Windows after they have been downloaded. I am seeing the group:501 and user:nobody as the owner (I’m not sure this is supposed to be like that but…). Is it possible to add something to the script that would change the owner to root.root?

  6. 6 Pete

    Never mind. I went into the Transmission.sh file and changed the user and group there….

  7. 7 Stekam

    Thanks for this nice scripts…

    However i would need some additional features:

    - Move completed downloaded files to another directory …

    Could you give me the technical link to TRANSMISSION so that i can look by myself too…

    Thanks…

  8. 8 Rongchang You

    Thanks a lot for the script. But it does not work in my DNS 323. I copy three files to the folder and create media folders. Nothing happend. When I examed the logs, there is only one unpack.log

    wc: No such file or directory
    [: 1: unknown operand

  9. 9 zaphod99

    @Rongchang You

    I had the same errors from unpacker.sh as you; had to use the full path (/ffp/bin/wc) to “wc” to resolve.

    Cheers…

  10. 10 Aizal

    Hi, thank you for this wonderful script.
    Only that I need help from any of you to tell me how did you make transmissions detect the torrents?

    THIS IS MY TORRENTWATCHDOG.SH
    #!/bin/sh
    ###########################################################################
    # script to monitor a selection of directories for new .torrent files.
    # if found, queue them up in transmission
    # and when done downloading, pause the torrent
    # w 10/20/08 horto
    # u 10/29/08 horto - implmented “make transmission stop after seeding 1:1″
    # u 10/29/08 horto - v2.0, do away with /torrents and /incoming dirs, and
    # just monitor /media/movies, /media/TV and /media/mp3
    # directories for torrents so I don’t have to manually
    # organize everything later!
    # u 11/06/08 horto - fixed bug with awk not being found via cron
    ###########################################################################
    TORRENTDIRS=”/mnt/HD_a2/media/movies /mnt/HD_a2/media/tv /mnt/HD_a2/media/mp3″
    LOG=/mnt/HD_a2/logs/torrentwd.log
    TRANSMISSION_REMOTE=/ffp/bin/transmission-remote

    # check each incoming TORRENTDIR for new .torrents
    for DIR in $TORRENTDIRS; do
    for FILE in $DIR/*.torrent; do

    # set download dir to current working dir
    $TRANSMISSION_REMOTE -w $DIR

    # pick out .torrent files and queue them up
    if [ “$FILE” != “$DIR/*.torrent” ]; then
    echo [`date`] “$FILE” added to queue. >> $LOG
    $TRANSMISSION_REMOTE -a “$FILE”
    rm “$FILE”
    echo [`date`] “$FILE” deleted. >> $LOG
    sleep 1
    fi
    done
    done

    # stop completed downloads
    for i in `/ffp/bin/transmission-remote -l | grep Done | grep Seeding | grep -v Ratio | /ffp/bin/awk ‘{print $1}’”`; do
    echo [`date`] stopping torrent id $i >> $LOG
    $TRANSMISSION_REMOTE -t $i -S
    done

    exit 0

    UNPACKER.SH
    #!/bin/sh
    ##############################################################################
    # —[ unpacker.sh ] —
    # script to look for rar files inside a specific directory.
    # if found, unrar them
    # w 10/29/08 horto
    ##############################################################################
    DLDIR=/mnt/HD_a2/media
    LOG=/mnt/HD_a2/logs/unpack.log
    UNRAR=/ffp/bin/unrar

    # quick and dirty check to make sure no active downloads.
    # because we don’t want to unrar/delete files that may be actively downloading!
    if [ `/ffp/bin/transmission-remote -l | wc -l` -gt 1 ]; then
    # stop, because a download is active.
    exit 0

    else
    # continue; because there are no active downloads.
    # check incoming DLDIR
    for FILE in `find $DLDIR -name “*.rar”`; do
    if [ “$FILE” != “*.rar” ]; then
    # shell-fu to extract to path containing the rar
    FILENAME=`expr //$FILE : ‘.*/\(.*\)’`
    UNPACKDIR=`echo $FILE | sed -e s/$FILENAME//g`
    echo [`date`] Extracting “$FILE” … >> $LOG

    # unrar file to the directory its sitting in
    $UNRAR x -y “$FILE” “$UNPACKDIR” >> /dev/null 2>&1
    echo [`date`] … done extracting. >> $LOG

    # cleanup - remove the rar file(s)
    # note: match .rar, .r01, .r02 … etc
    echo [`date`] Removing “$FILENAME and rar files.” >> $LOG
    for j in `find $UNPACKDIR -name “*.r??”`; do
    rm $j
    done
    fi
    done

    exit 0
    fi

    MY EDITCRON.SH
    #!/bin/sh
    ##############################################################################
    # —-[ editcron.sh ]—-
    # script to keep cronjobs persistent (e.g. after reboot)
    # NOTE: put this in /mnt/HD_a2/ffp/start/ and make it executable.
    # w 22/10/08 horto
    # ref/credit: http://tinyurl.com/5m2349 - thanks chumby!
    #############################################################################
    FFP=/mnt/HD_a2/ffp
    CRONTXT=$FFP/etc/crontab.txt

    # start with existing crontab
    # note: on a fresh reboot, this will always have been reset to standard
    /bin/crontab -l > $CRONTXT

    # add cronjobs here preceeded by /bin/echo.
    # don’t forget to enclose them in double quotes.
    /bin/echo “0 * * * * /ffp/var/scripts/torrentwatchdog.sh >> /mnt/HD_a2/logs/torrentwd.log 2>&1″ >> $CRONTXT
    /bin/echo “30 3 * * * /ffp/var/scripts/unpacker.sh >> /mnt/HD_a2/logs/unpack.log 2>&1″ >> $CRONTXT

    # install the new crontab
    /bin/crontab $CRONTXT

    # clean up
    /bin/rm $CRONTXT

    PROBLEM:
    I put my torrents inside /media/, /media/movies/, /media/tv/, /media/mp3/ but transmission did not pickup any of them.

    I tried uploading a torrent via transmission webgui itself and I checked the torrent was saved in /.transmission-daemon/torrents/ folder.

    How to make transmission detect torrents from the media folders??

    PLEASE HELP.

  11. 11 Aizal

    Just an update, I tried starting torrentwatchdog.sh and unpacker.sh manually
    “/ffp/var/scripts/torrentwatchdog.sh start
    /ffp/var/scripts/unpacker.sh start”

    But both return almost the same error. PLEASE HELP.

    root@dlink-0A78F3:/mnt/HD_a2/.transmission-daemon# /ffp/var/scripts/torrentwatch
    dog.sh start
    [10:03:05.589] JSON parser failed at line 1, column 1: “401: Unautho”
    [10:03:05.593] transmission-remote: Unable to parse response “401: UnauthorizedUnauthorized User”
    [10:03:05.788] JSON parser failed at line 1, column 1: “401: Unautho”
    [10:03:05.791] transmission-remote: Unable to parse response “401: UnauthorizedUnauthorized User”
    [10:03:05.970] JSON parser failed at line 1, column 1: “401: Unautho”
    [10:03:05.973] transmission-remote: Unable to parse response “401: UnauthorizedUnauthorized User”
    [10:03:06.277] JSON parser failed at line 1, column 1: “401: Unautho”
    [10:03:06.280] transmission-remote: Unable to parse response “401: UnauthorizedUnauthorized User”

    root@dlink-0A78F3:/mnt/HD_a2/.transmission-daemon# /ffp/var/scripts/unpacker.sh
    start
    [09:52:30.225] JSON parser failed at line 1, column 1: “401: Unautho”
    [09:52:30.229] transmission-remote: Unable to parse response “401: UnauthorizedUnauthorized User”

  12. 12 admin

    @Aizal: dude. this is the new transmission daemon complaining about authorization. you need to follow the steps here to update the settings accordingly. apologies i haven’t updated my scripts accordingly, but i use the older version of transmission.

  13. 13 Aizal

    Hey horto,

    Thanks for replying. I just amazed that you replied at almost instantly after I sent an email to you. :P
    Anyway, I downgrade my transmission and try running torrentwatchdog manually.
    Here what I got:
    root@dlink-0A78F3:/mnt/HD_a4/packages# /ffp/var/scripts/torrentwatchdog.sh start
    transmission-remote: Unable to parse response “401: UnauthorizedUnauthorized User”
    transmission-remote: Unable to parse response “401: UnauthorizedUnauthorized User”
    transmission-remote: Unable to parse response “401: UnauthorizedUnauthorized User”
    transmission-remote: Unable to parse response “401: UnauthorizedUnauthorized User”

    So, Since the error seems similar to my initial error, I re-upgrade transmission to the latest version.
    Could you help?

  14. 14 Aizal

    Oh, forgot to ask which version of Transmission you are currently using and the auto downloader working on it?
    I think if nothing works then I might as well downgrade my transmission version.
    Just need this function working.

    Thanks.

  15. 15 admin

    @Aizal, clearly this:

    transmission-remote: Unable to parse response “401: UnauthorizedUnauthorized User”
    transmission-remote: Unable to parse response “401: UnauthorizedUnauthorized User”
    transmission-remote: Unable to parse response “401: UnauthorizedUnauthorized User”
    transmission-remote: Unable to parse response “401: UnauthorizedUnauthorized User”

    is a transmission error. (it’s being spewed by transmission-remote).

    it’s because with the newer versions of transmission, you must specify a user and password to connect.

    what this means is that with the torrentwatchdog script, you have to update the parameters being passed to transmission, like this:

    TRANSMISSION_REMOTE=’/ffp/bin/transmission-remote -n user:passwd’

    Replace user:passwd with your username and password as you set up in transmission.

    This all only applies to transmission 1.40 and higher. I’m using transmission 1.34. So this is all based on what other people have told me :)

  16. 16 Aizal

    By username and password, do you mean the one in settings.json? What if I did not set any?
    So I add username and password and still get the error.
    TORRENTDIRS=”/mnt/HD_a2/media/movies /mnt/HD_a2/media/tv /mnt/HD_a2/media/mp3″
    LOG=/mnt/HD_a2/logs/torrentwd.log
    TRANSMISSION_REMOTE=’/ffp/bin/transmission-remote -n nyunyu:742258′ –> is it ” or ‘ ?

    I tried this command and got the same error.
    root@dlink-0A78F3:/mnt/HD_a2/ffp/var/scripts# /ffp/bin/transmission-remote -l
    [22:54:41.871] JSON parser failed at line 1, column 1: “401: Unautho”
    [22:54:41.875] transmission-remote: Unable to parse response “401: UnauthorizedUnauthorized User”

    Can you give me the link to transmission v1.34?

  17. 17 Aizal

    I keep banging my head on the wall because of this error.
    It turned out a simple fix solved the problem. I put the wrong password.

    So, if you are using rpc authorization (username and password), then for every transmission-remote line, add -n username:passwd.

    Now I got it working with Transmission 1.52.

    BUT!

    Whenever I put new torrents into the folder, it does not detect instantly.
    It will only detect whenever I stop or start torrentwatchdog.sh. Any idea why?

    The script deleted the torrent once it was queued, so I modify the script to move the torrent instead so in case there is something wrong, I can just copy the torrent again.

    in torrentwatchdog.sh, I changed this part:
    # pick out .torrent files and queue them up
    if [ “$FILE” != “$DIR/*.torrent” ]; then
    echo [`date`] “$FILE” added to queue. >> $LOG
    $TRANSMISSION_REMOTE -a “$FILE”
    rm “$FILE”
    echo [`date`] “$FILE” deleted. >> $LOG
    sleep 1
    fi
    done
    done

    to this:
    # pick out .torrent files and queue them up
    if [ “$FILE” != “$DIR/*.torrent” ]; then
    echo [`date`] “$FILE” added to queue. >> $LOG
    $TRANSMISSION_REMOTE -a “$FILE”
    mv “$FILE -f $USED_TORRENTS/$FILE”
    echo [`date`] “$FILE” moved to “$USED_TORRENTS”. >> $LOG
    sleep 1
    fi
    done
    done

    Can you check my code so the file will actually moved?
    (currently it does not moved)

    Thanks.

  18. 18 Matthew

    Is there a way to delete a cron job completely on the DNS-323? I would like to manually run the torrentwatchdog script.

    Thanks,
    Matthew

  19. 19 jumperson

    Is there a way to change the ratio from 1 to something else? If I try and download something that has a lot of seeders and no leechers, the unpacker.sh script will never run. Any way to change the script to check the status of it for being done downloading instead?

    Also, the editcron.sh script which has the timing of when to check, does that mean it will pull the NAS out of sleep mode every hour on the hour? And then again every 3 hours on the 30 minute mark? Is that what the below means? Or is it every hour on the hour and then every 3.5 hours?

    /bin/echo “0 * * * * /ffp/var/scripts/torrentwatchdog.sh >> /mnt/HD_a2/logs/torrentwd.log 2>&1″ >> $CRONTXT
    /bin/echo “30 3 * * * /ffp/var/scripts/unpacker.sh >> /mnt/HD_a2/logs/unpack.log 2>&1″ >> $CRONTXT

  20. 20 admin

    @jumperson:

    0 * * * * is every hour on the hour
    30 3 * * * is every day at 3:30am

    you can change the values to whatever you prefer. see http://www.scrounge.org/linux/cron.html

  21. 21 jumperson

    Thanks for the reply Admin! Looking at the link you posted, I can’t seem to figure out a way to have something run every 3 hours. Is it possible to schedule something with the cron job for every 3 hours? Do you know what I should be putting for the format for that?

    0 3 * * * is every day at 3am
    3 * * * * is every 3 minutes past the hour…i think.

    Any ideas?

  22. 22 admin

    @jumperson,

    try 0 */3 * * *

  23. 23 Brusko

    Hello Stekam (Feb 5th, 2009 at 5:40 am) and all here. I also thought how to
    “Move completed downloaded files to another directory …” (for examlpe Volume_1\BT\complete directory same with BitTorrent directory made by D-Link). Because of numbers of torrents I split downloading/ed torrents into the categories/dictionaries (#cart-cartoons, #music, #doc-documentary etc.)
    I have …\Volume_1\BT\torrents_to_add\:
    #cart\
    #clip\
    #cz&sk\
    #dab\
    #doc\
    #dvd\
    #hd\
    #install\
    #mp3\
    #ser\
    #tit\
    #xxx\
    and same structure in …\Volume_1\BT\complete\
    #cart\
    #clip\
    #cz&sk\
    #dab\
    #doc\
    #dvd\
    #hd\
    #install\
    #mp3\
    #ser\
    #tit\
    #xxx\
    For adding and moveing compled download I use same torrentwatchdog.sh where I add “moving part”. I have just one problem and that is this script move files when I’m loged in. When it is runnig by cron schedule it just add new torrent for downloading stop completed but don’t move completed. I heve to log in time to time and run this script. One more feature. When I move downloaded file or directory I create simlink to prevent Transmission download same torrent one more time, after restarting download. So when i want to start seeding some torrent I can just enable seeding in Transmission GUI (of coure i have to disable scheduled stoping of seeding in this script).

    #!/bin/sh
    ###########################################################################
    # script to monitor a selection of directories for new .torrent files.
    # if found, queue them up in transmission
    # and when done downloading, pause the torrent
    # w 10/20/08 horto
    # u 10/29/08 horto - implmented “make transmission stop after seeding 1:1″
    # u 10/29/08 horto - v2.0, do away with /torrents and /incoming dirs, and
    # just monitor /media/movies, /media/TV and /media/mp3
    # directories for torrents so I don’t have to manually
    # organize everything later!
    # u 11/06/08 horto - fixed bug with awk not being found via cron
    ###########################################################################
    TORRENTDIRS=”/mnt/HD_a2/BT/torrents_to_add /mnt/HD_a2/BT/torrents_to_add/\#cart /mnt/HD_a2/BT/torrents_to_add/\#clip /mnt/HD_a2/BT/torrents_to_add/\#cz\&sk /mnt/HD_a2/BT/torrents_to_add/\#dab /mnt/HD_a2/BT/torrents_to_add/\#doc /mnt/HD_a2/BT/torrents_to_add/\#dvd /mnt/HD_a2/BT/torrents_to_add/\#hd /mnt/HD_a2/BT/torrents_to_add/\#install /mnt/HD_a2/BT/torrents_to_add/\#mp3 /mnt/HD_a2/BT/torrents_to_add/\#ser /mnt/HD_a2/BT/torrents_to_add/\#tit /mnt/HD_a2/BT/torrents_to_add/\#xxx”
    LOG=/mnt/HD_a2/BT/torrentwd.log
    LOG2=/mnt/HD_a2/BT/torrentmv.log
    LOG3=/mnt/HD_a2/BT/debugmv.log
    echo “” > $LOG3

    TRANSMISSION_REMOTE=/ffp/bin/transmission-remote

    # check each incoming TORRENTDIR for new .torrents
    for DIR in $TORRENTDIRS; do
    for FILE in $DIR/*.torrent; do

    # set download dir to current working dir
    $TRANSMISSION_REMOTE -w $DIR

    # pick out .torrent files and queue them up
    if [ “$FILE” != “$DIR/*.torrent” ]; then
    echo [`date`] “$FILE” added to queue. >> $LOG
    $TRANSMISSION_REMOTE -a “$FILE”
    rm “$FILE”
    echo [`date`] “$FILE” deleted. >> $LOG
    sleep 1
    fi
    done
    done

    # stop completed downloads when “Seeding”
    #for i in `/ffp/bin/transmission-remote -l | grep Done | grep Seeding | grep -v Ratio | /ffp/bin/awk ‘{print $1}’”`; do

    # stop completed downloads when “100%”
    for i in `/ffp/bin/transmission-remote -l | grep Done | grep 100% | grep -v Ratio | grep -v Stopped | /ffp/bin/awk ‘{print $1}’`; do
    echo [`date`] stopping torrent id $i >> $LOG
    $TRANSMISSION_REMOTE -t $i -S
    done

    # move completed downloads
    /ffp/bin/transmission-remote -l | grep Done | grep 100% | grep -v Ratio | /ffp/bin/cut -c 70-| while read i
    do
    ciel_ln=`find /mnt/HD_a2/BT/complete/ -name “$i”` >> $LOG2
    echo ciel_ln “$ciel_ln” meno “$i” >> $LOG3
    if [ “$ciel_ln” == “” ]; then
    zdroj_org=`find /mnt/HD_a2/BT/torrents_to_add/ -name “$i”` >> $LOG2
    echo zdroj_org “$zdroj_org” meno “$i” >> $LOG3
    if [ “$zdroj_org” != “” ]; then
    ciel_ln=`echo “$zdroj_org” | sed ’s/torrents_to_add/complete/g’ | awk -F”\$i” ‘{print $1}’` >> $LOG2
    echo ciel_ln “$ciel_ln” meno “$i” >> $LOG3
    echo [`date`] moving “$zdroj_org” to “$ciel_ln” torrent >> $LOG2
    `mv “$zdroj_org” “$ciel_ln”`
    echo [`date`] moving completed torrent $i >> $LOG3
    ciel_ln=`echo “$zdroj_org” | sed ’s/torrents_to_add/complete/g’` >> $LOG2
    echo [`date`] create link “$ciel_ln” to “$zdroj_org” >> $LOG2
    `ln -s “$ciel_ln” “$zdroj_org”`
    fi
    fi
    done

    exit 0

  24. 24 km

    Hey,

    good work, much appreciated. thats all.

    km

  25. 25 Joe in VA

    @Brusko,
    I like the approach you have for moving scripts, but I was hoping to do something a little differently.
    WARNING: Linux Noob :)

    I have my files for shows downloaded organized by show name. The results of the download are something like
    “Kids Show S02E03.avi”
    I’ll have “Parents show 1 S03E01.avi” “Dad Show S01E01.avi” etc.

    Once the show is 100% complete, I’d like to move it to a particular directory, Like this

    /ffp/bin/transmission-remote -l | grep Done | grep 100% | grep -v Ratio | /ffp/bin/cut -c 70-| while read i
    do
    ciel_ln=`find /mnt/HD_a2/Downloads -name “$i”`

    If $i has ‘Kids’ in the name I want to move it to \TV\KidsShow folder.
    If $i has ‘Parent’ in the name I want to move it to \TV\Parent folder.

    I’ve been trying to get the right syntax for a substring, but just don’t have it.

    Any help would be appreciated..

Leave a Reply