script partially running after download complete

Ask for help and report issues not specific to either the Mac OS X or GTK+ versions of Transmission
Post Reply
ggeremy
Posts: 4
Joined: Sat Oct 23, 2010 2:58 pm

script partially running after download complete

Post by ggeremy »

Hi everybody !

I have a problem with a really simple script partially running after download complete.
I just want to list all the torrent and get their ID.

Code: Select all

#!/bin/bash

TR=/usr/local/bin/transmission-remote
AUTH="host:port --auth=user:password"
LIST=`$TR $AUTH -l | sed -e '1d;$d;s/^ *//' | cut -s -d " " -f1`
LOGPATH=/media/sdg/home/geremy/private/log/script.log

echo `date` >> $LOGPATH

for ID in $LIST; 
do
	echo $ID >> $LOGPATH
  	#$TR $AUTH -t $ID -r
done
The script is running, write the date in the log file. But the LIST is empty.
However, when I test the script manually the script works fine.

Can you help me ?

Thanks
gunzip
Posts: 272
Joined: Wed May 05, 2010 2:12 am

Re: script partially running after download complete

Post by gunzip »

try modifying script..

#!/bin/bash
{
<your script>
} &

so it runs in background (&) as it may be hanging on the transmission-remote command. something like this:

Code: Select all

#!/bin/bash

{

    TR=/usr/local/bin/transmission-remote
    AUTH="host:port --auth=user:password"
    LIST=`$TR $AUTH -l | sed -e '1d;$d;s/^ *//' | cut -s -d " " -f1`
    LOGPATH=/media/sdg/home/geremy/private/log/script.log

    echo `date` >> $LOGPATH

    for ID in $LIST;
    do
       echo $ID >> $LOGPATH
     #$TR $AUTH -t $ID -r
    done

} &

# end of script



there was a similar issue in this forum and this solved it.
ggeremy
Posts: 4
Joined: Sat Oct 23, 2010 2:58 pm

Re: script partially running after download complete

Post by ggeremy »

It's working like a charm !
Thank you

Now I have a second question, I saw on other scripts that there is a variable $TR_TORRENT_NAME.
I suppose this is the torrent completed. Are there more variables like this ?

Thank you
gunzip
Posts: 272
Joined: Wed May 05, 2010 2:12 am

Re: script partially running after download complete

Post by gunzip »

ggeremy wrote: Now I have a second question, I saw on other scripts that there is a variable $TR_TORRENT_NAME.
I suppose this is the torrent completed. Are there more variables like this ?
yes, on completion of any torrent the following variables specific to that torrent are passed to the script:

TR_TORRENT_DIR
TR_TIME_LOCALTIME
TR_TORRENT_ID
TR_TORRENT_HASH
TR_APP_VERSION
TR_TORRENT_NAME

try this simple one-line script and you can see them written in the /tmp/TR_LOG file:

Code: Select all

#!/bin/sh
env | grep '^TR_' >> "/tmp/TR_LOG" 2>&1
i'm running Linux so i don't how or if these scripts work on a Mac.
ggeremy
Posts: 4
Joined: Sat Oct 23, 2010 2:58 pm

Re: script partially running after download complete

Post by ggeremy »

Hi,
I need your help again. I've made some modifications modifications in my script
in order to send the data of a completed torrent on remote host.

Code: Select all

#!/bin/bash
{

#COMMANDE
RSYNC=/usr/bin/rsync

#DATE
DAY=`date +"%F"`
TIME=`date +"%T"`

#LOGFILE
RSC="/path/to/log/rsync_${DAY}_${TIME}.log"
HST="/path/to/log/history_${DAY}.log"
ERR="/path/to/log//error_${DAY}.log"

#DIRECTORIES AND REMOTE HOST
DATADIR="/path/to/data/"
DHOST="user@remote-host:/media/downloads/"

#TORRENT PATH
PATH="$DATADIR$TR_TORRENT_NAME"
#OR THIS, 
#PATH=$(echo "$DATADIR$TR_TORRENT_NAME" | sed 's/ /\\ /g')
#BUT I DON'T KNOW IF IT'S A GOOD IDEA

echo $TIME $TR_TORRENT_NAME >> $HST
echo "Path: "$PATH >> $HST

if [ -e "$PATH" ]; then
  	if [ -d "$PATH" ] ; then		
 		$RSYNC -ruv $PATH $DHOST >> $RSC 2>> $ERR &
  	else
 		$RSYNC -uv $PATH $DHOST >> $RSC 2>> $ERR & 
  	fi;
fi;
} &
The script's running until the first if, then nothing.
So I tried to remove the if tests and just let the rsync command but nothing.
Can someone help me ?

Other thing, rsync via ssh doesn't require a password in this case, because I've setup a private et public key between the two hosts.
gunzip
Posts: 272
Joined: Wed May 05, 2010 2:12 am

Re: script partially running after download complete

Post by gunzip »

ggeremy wrote:

Code: Select all

if [ -e "$PATH" ]; then
  	if [ -d "$PATH" ] ; then		
 		$RSYNC -ruv $PATH $DHOST >> $RSC 2>> $ERR &
  	else
 		$RSYNC -uv $PATH $DHOST >> $RSC 2>> $ERR & 
  	fi;
fi;
first thing, you should always put quotes "" around the dir/file paths in your scripts as torrent names often have spaces and/or non-standard characters in them. when this happens your script is definitely going to break on the rsync command. better to do this:

$RSYNC -ruv "$PATH" "$DHOST" >> "$RSC" 2>> "$ERR" &


second thing, this bit of code looks like a bad idea:

PATH="$DATADIR$TR_TORRENT_NAME"

well $PATH is an important environmental variable passed to the script, and it's very confusing to define it as the torrent location. change it everywhere to something like DATAPATH instead:

DATAPATH="$DATADIR$TR_TORRENT_NAME"

$RSYNC -ruv "$DATAPATH" "$DHOST" >> "$RSC" 2>> "$ERR" &
ggeremy
Posts: 4
Joined: Sat Oct 23, 2010 2:58 pm

Re: script partially running after download complete

Post by ggeremy »

It's working !

Thanks a lot :wink:
Post Reply