Please note the new address for this forum : forum.excito.org. The old address redirects here but I don't know for how long. Thanks !
New user's registration have been closed due to high spamming and low trafic on this forum. Please contact forum admins directly if you need an account. Thanks !

Transmission on B3 - Environment variables + running script

Got problems with your B2 or B3? Share and get helped!
Post Reply
paq
Posts: 2
Joined: 04 May 2011, 17:58

Transmission on B3 - Environment variables + running script

Post 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!
Cheeseboy
Posts: 789
Joined: 08 Apr 2007, 12:16

Re: Transmission on B3 - Environment variables + running scr

Post 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
paq
Posts: 2
Joined: 04 May 2011, 17:58

Re: Transmission on B3 - Environment variables + running scr

Post 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!
RandomUsername
Posts: 904
Joined: 09 Oct 2009, 18:49

Re: Transmission on B3 - Environment variables + running scr

Post 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.
Post Reply