Page 1 of 1

Transmission on B3 - Environment variables + running script

Posted: 04 May 2011, 20:11
by paq
Hi!

I have built and installed torrent client Transmission (daemon) version 2.21 (11855) on my B3. It works very well except for two problems. I have searched the web and in particular Transmissions forums and other support sites for help but finding nothing on the topic led me to think if my problems maybe have something with the B3 to do.

So, first off: When a download completes Transmission will set some environment variables about the completed torrent that can be used for scripts and so on. However, when I go through all the variables (like TR_TORRENT_NAME and try to echo them, nothing is shown. Even trying echo $TR_APP_VERSION which should work all the time shows that nothing is set. Could this be because of some limitation of the B3?

Secondly, when a download finishes Transmission is configured to run a script. For now I have a simple script which only saves date and environment variables:

Code: Select all

#! /bin/sh 
{
date >> info.log
echo "Torrent complete" >> info.log
echo Torrent Name is "$TR_TORRENT_NAME" >> info.log
echo Torrent ID is "$TR_TORRENT_ID" >> info.log
} &
If I check syslog I can see that the script was called when a torrent completed, Calling script "/.../script.sh", but nothing was written to info.log. I can run the script with result (except for the environment variables) with sh script.sh in the terminal. I have used chmod -R 777 on the folder where the script and the log file are but without success. Any clues?


UPDATE: Actually, while writing this post somehow data including correct environment variables was written to the info.log file. However, this was only done for some of the already completed torrents and not for anything added after reboot. Checking the processes, there was two transmission-daemon running, one under user root and one under user 114. The latter one had successful "Calling script"-lines in syslog while the ones associated with root were unsuccessful. The problems do still exists though since I haven't been able to recreate this circumstances with reboots since. I'll be thankful for any help possible!

Re: Transmission on B3 - Environment variables + running scr

Posted: 05 May 2011, 07:32
by Cheeseboy
Hi paq,

Just some ideas:
I find that when writing scripts that will be invoked by the system (cron or otherwise), I always have to use absolute paths in order for it to work. E.g:

Code: Select all

/bin/date
rather than

Code: Select all

date
Also the output path is undefined...

You could also do this:

Code: Select all

grep --color=auto 114 /etc/passwd
On my system, the user is statd, and it hasn't got a home directory, so who knows where the output is going to end up?

Cheers,

Cheeseboy

Re: Transmission on B3 - Environment variables + running scr

Posted: 14 May 2011, 18:56
by paq
Thank you for your help Cheeseboy!

It turned out that using relative paths inside my script was the problem.

Writing the path of the file where data would be written as an absolute path solved it.

It now works like a charm! The environment variables are now picked up by the script upon torrent completion and then written to the right log-file :)

Thanks again for pointing out about the paths and for the quick reply!

Re: Transmission on B3 - Environment variables + running scr

Posted: 16 May 2011, 07:20
by RandomUsername
Just a bit extra. When writing scripts I always declare things like log files as variables at the beginning of the script. Something like

Code: Select all

LOGFILE=/home/user/log.log
and then set all outputs to

Code: Select all

command >> $LOGFILE
This way, the log file location can be changed fairly easily.