On completion script variables please help.

Ask for help and report issues not specific to either the Mac OS X or GTK+ versions of Transmission
Post Reply
dexus
Posts: 5
Joined: Thu Feb 11, 2010 2:41 pm

On completion script variables please help.

Post by dexus »

Hi.

I am in no way an accomplished script-writer, but this seemed to be in my range.. but alas! I just can't understand what I am doing wrong..
I am trying to read the $TR_TORRENT_DIR variable, and then ftp the downloaded files to my local ftp server, choosing a folder based on the string value.

I have tried several approaches, and the command function part works fine

Code: Select all

#!/bin/bash
lftp << EOF
open -u username,password my.ftp.site
mirror -R $TR_TORRENT_DIR/$TR_TORRENT_NAME /TV/
lcd $TR_TORRENT_DIR
cd /TV/
put $TR_TORRENT_NAME
bye
EOF
This works.. (btw. the reason for the double transfer on the same torrent is a workaround for when a torrent contains a file rather than a folder with files)

Now.. My If Then else statements does not seem to work, as it will not initiate any transfers when the code looks like this:

Code: Select all

#!/bin/bash

if [[ "$TR_TORRENT_DIR" == *data* ]]
then
        lftp << EOF
        open -u username,password my.ftp.site
        mirror -R $TR_TORRENT_DIR/$TR_TORRENT_NAME /TV/
        lcd $TR_TORRENT_DIR
        cd /TV/
        put $TR_TORRENT_NAME
        bye
        EOF

elif [[ "$TR_TORRENT_DIR" == *ptp* ]]
then
        lftp << EOF
        open -u username,password my.ftp.site
        mirror -R $TR_TORRENT_DIR/$TR_TORRENT_NAME /Movies/
        lcd $TR_TORRENT_DIR
        cd /Movies/
        put $TR_TORRENT_NAME
        bye
        EOF

elif [[ "$TR_TORRENT_DIR" == *0day* ]]
then
        lftp << EOF
        open -u username,password my.ftp.site
        mirror -R $TR_TORRENT_DIR/$TR_TORRENT_NAME /0day/
        lcd $TR_TORRENT_DIR
        cd /0day/
        put $TR_TORRENT_NAME
        bye
        EOF
else
        lftp << EOF
        open -u username,password my.ftp.site
        mirror -R $TR_TORRENT_DIR/$TR_TORRENT_NAME /Diverse/
        lcd $TR_TORRENT_DIR
        cd /Diverse/
        put $TR_TORRENT_NAME
        bye
        EOF
fi
I have tried several other solutions, like functions:

Code: Select all

#!/bin/bash

tvserie() {
        lftp << EOF
        open -u username,password my.ftp.site
        mirror -R $TR_TORRENT_DIR/$TR_TORRENT_NAME /TV/
        lcd $TR_TORRENT_DIR
        cd /TV/
        put $TR_TORRENT_NAME
        bye
        EOF
}

movies() {
        lftp << EOF
        open -u username,password my.ftp.site
        mirror -R $TR_TORRENT_DIR/$TR_TORRENT_NAME /Movies/
        lcd $TR_TORRENT_DIR
        cd /Movies/
        put $TR_TORRENT_NAME
        bye
        EOF
}

0day() {
        lftp << EOF
        open -u username,password my.ftp.site
        mirror -R $TR_TORRENT_DIR/$TR_TORRENT_NAME /0day/
        lcd $TR_TORRENT_DIR
        cd /0day/
        put $TR_TORRENT_NAME
        bye
        EOF
}


diverse() {
        lftp << EOF
        open -u username,password my.ftp.site
        mirror -R $TR_TORRENT_DIR/$TR_TORRENT_NAME /Diverse/
        lcd $TR_TORRENT_DIR
        cd /Diverse/
        put $TR_TORRENT_NAME
        bye
        EOF
}

if [ $TR_TORRENT_DIR = "/my/tv/series/folder/" ]; then
       tvserie
elif [ $TR_TORRENT_DIR = "/my/movie/folder/" ]; then
       movies
elif [ $TR_TORRENT_DIR = "/my/0day/folder/" ]; then
       0day
else
       diverse
fi
Any help would be greatly appreciated.

.dexus.
dexus
Posts: 5
Joined: Thu Feb 11, 2010 2:41 pm

Re: On completion script variables please help.

Post by dexus »

Thanks for the reply..

Still does not work, tho.. This is the current "non working" code..

Code: Select all

#!/bin/bash

if [[ "$TR_TORRENT_DIR" == *data* ]];
then
        lftp << EOF
        open -u username,password my.ftp.site
        mirror -R $TR_TORRENT_DIR/$TR_TORRENT_NAME /TV/
        lcd $TR_TORRENT_DIR
        cd /TV/
        put $TR_TORRENT_NAME
        bye
        EOF

elif [[ "$TR_TORRENT_DIR" == *ptp* ]];
then
        lftp << EOF
        open -u username,password my.ftp.site
        mirror -R $TR_TORRENT_DIR/$TR_TORRENT_NAME /Movies/
        lcd $TR_TORRENT_DIR
        cd /Movies/
        put $TR_TORRENT_NAME
        bye
        EOF

elif [[ "$TR_TORRENT_DIR" == *0day* ]];
then
        lftp << EOF
        open -u username,password my.ftp.site
        mirror -R $TR_TORRENT_DIR/$TR_TORRENT_NAME /0day/
        lcd $TR_TORRENT_DIR
        cd /0day/
        put $TR_TORRENT_NAME
        bye
        EOF
else
        lftp << EOF
        open -u username,password my.ftp.site
        mirror -R $TR_TORRENT_DIR/$TR_TORRENT_NAME /Diverse/
        lcd $TR_TORRENT_DIR
        cd /Diverse/
        put $TR_TORRENT_NAME
        bye
        EOF
fi
This code works..:

Code: Select all

#!/bin/bash

        lftp << EOF
        open -u username,password my.ftp.site
        mirror -R $TR_TORRENT_DIR/$TR_TORRENT_NAME /TV/
        lcd $TR_TORRENT_DIR
        cd /TV/
        put $TR_TORRENT_NAME
        bye
        EOF
I have no idea why the top script doesn't work.. (I did remember to put in my real usernames etc.. :-))
If anyone have any idea, or have something similar that DOES work using lftp (ncftp is not an option on my seedbox atm.), please help.

The point of this is of course to sort the downloads automatically based on which folder the torrent was assigned to in Transmission..

Thank you!

.dexus.
dexus
Posts: 5
Joined: Thu Feb 11, 2010 2:41 pm

Re: On completion script variables please help.

Post by dexus »

Thanks for replying again x190, but I found the flaw.

When using bash heredocs, the end phrase needs to be by itself on the line, with no whitespace.
My EOF's was indented, and that caused the error.

Now this script works flawlessly, and I can highly recommend this to anyone who need a simple download (or rather upload) script.
The big advantage to this script, as opposed to a local ftp script that syncs every so often, is 1: you get your files transferred as soon as they are complete. 2: You can unpack, modify, move or whatever the files locally without having a sync script download the files again. This will let you continue to seed with the seedbox without having to move the files to another location that is not synced.

Here's the working script:

Code: Select all

#!/bin/bash

if [[ "$TR_TORRENT_DIR" == *your_seedbox_tvseries_folder* ]];
then
        lftp << EOF
        open -u username,password my.ftp.site
        mirror -R $TR_TORRENT_DIR/$TR_TORRENT_NAME /your_local_tvseries_folder/
        lcd $TR_TORRENT_DIR
        cd /TV/
        put $TR_TORRENT_NAME
        bye
EOF

elif [[ "$TR_TORRENT_DIR" == *your_seedbox_movies_folder* ]];
then
        lftp << EOF
        open -u username,password my.ftp.site
        mirror -R $TR_TORRENT_DIR/$TR_TORRENT_NAME /your_local_movies_folder/
        lcd $TR_TORRENT_DIR
        cd /Movies/
        put $TR_TORRENT_NAME
        bye
EOF

elif [[ "$TR_TORRENT_DIR" == *your_seedbox_0day_folder* ]];
then
        lftp << EOF
        open -u username,password my.ftp.site
        mirror -R $TR_TORRENT_DIR/$TR_TORRENT_NAME /your_local_0day_folder/
        lcd $TR_TORRENT_DIR
        cd /0day/
        put $TR_TORRENT_NAME
        bye
EOF
else
        lftp << EOF
        open -u username,password my.ftp.site
        mirror -R $TR_TORRENT_DIR/$TR_TORRENT_NAME /your_local_anything_else_folder/
        lcd $TR_TORRENT_DIR
        cd /Diverse/
        put $TR_TORRENT_NAME
        bye
EOF
fi
The "local folders" refer to folders in your ftp server, and the "seedbox folders" refer to the folders you have chosen to have transmission put your download.

.dexus.
Post Reply