For some reason transmission's watch-dir functionality doesn't work for me (I tried a few "solutions" I found but nothing worked). So I made myself a script to supply for that (note that I put this script in my crontab to run hourly, so I needed to add fullpaths for everything):


cd $folder

count=$(ls -1 *.torrent 2>/dev/null | wc -l)
if [ $count != 0 ];then
    echo $count torrents files found
    for torrent in '*.torrent'; do
        echo adding $torrent
        transmission-remote -n 'transmission:transmission' -a $folder/"$torrent"
        rm $folder/$torrent
    echo no torrents found

What I got with this script is that it works if there is only 1 torrent file. But if there is 2 or more, then only 1 of them is added, all of them are removed and the line echo adding $torrent shows all torrents.

What am I doing wrong?

  • Use inotify-wait. – jasonwryan Jul 9 '18 at 1:49

I suspect that the line

for torrent in '*.torrent'; do

is not expanding to a list of files because you've enclosed it in quotes. It expands later each time $torrent is used, but this passes all of your files to transmission at once.

Rewrite this line as

for torrent in *.torrent; do

I also recommend using nullglob. See for loop glob mishaps.

Also, inotify-wait can be used to trigger a shell script when a file is created in a directory.

  • thanks, i removed quotes and now it works fine. Could you expand more in how to use inotify-wait?, a quick search and i couldn't see how to monitor only *.torrent creations, but i now that it should be with -e create option. – kurokirasama Jul 9 '18 at 2:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.