0

In transmission-gtk there is an option can run script: Edit > Preferences > Downloading > Call script when torrent is completed.

Recently, I found this script that I do not know how to make it work under transmission. According to the program description, the script does not turn off the system, but it can kill transmission after all torrents are done. that's enough for me because I can chain "turning off" to "closing transmission" by &&.

Now, may you, guys, help me to run this php script under transmission?

this is an example mentioned by the script author: php.exe Transmission_Quit.php --port=9999 --hostname=192.168.0.1; what does this mean?! how should I use it? Should I point it to "Call script when torrent is completed" option directly?

5
  • The mention of "php.exe" in the "example mentioned by the script author" seems to have something to do with a Windows based system. Are you trying this in a Windows system? in Ubuntu php.exe may fail. Please inform. Thank you. Apr 30, 2013 at 13:05
  • :o Is transmission available on windows?
    – mini
    Apr 30, 2013 at 14:37
  • This link says so: Transmission-Qt Win is a build of transmission-qt for Windows. ==> sourceforge.net/projects/trqtw Apr 30, 2013 at 14:55
  • Good news, I'll share it to my friends. However, the reference hints: PHP CLI script --> cli
    – mini
    Apr 30, 2013 at 15:35
  • there is also "cli" in Windows. Formerly known as command.com and more recently known as cmd.com console. :) Additionally, the php code that you refer can be used both in Windows or Linux. :) May 6, 2013 at 23:49

1 Answer 1

3

I am leaving this in order to follow up the original question which is asking to run a specific php script. But a workaround is provided in the New Recipe section in order to solve the main problem.

Please try this and inform on your results, after which this answer may be changed or deleted:

At a certain moment your password may be asked.

  1. First of all, let's create a file called script.php by dropping in a terminal sudo gedit script.php (remember that you can drop this file in whatever folder you wish but for testing purposes your home folder will be good).
  2. In the file, let's copy/paste the contents of the script that you mention. Save the file and close it down.
  3. Now let's give the file the proper file permissions and the execution permission also by dropping the next two lines in a terminal, one line at once.

    sudo chmod 755 script.php

    sudo chmod a+x script.php

  4. Now, let's install php5-cli by dropping in a terminal sudo apt-get install php5-cli and let's wait the terminal to finish the install process.

Once php5-cli is installed we can test the script by invoking php script.php --port=9999 --hostname=192.168.0.1; in a terminal, but it will be better if you do it from inside of Transmission.

php5-cli is a command line interpreter for the PHP5 Scripting Language and it is useful to run php scripts like this, it is more like the php.exe file for Windows, the one that you refer on your original question.

I hope you succeed but please inform on your results in order to provide the proper support or delete this answer if not useful.

Addendum

After reading your comments, I give you this fast-food recipe for the php script.

First of all I need to explan certain things of the example given by the script's author, as follows:

script.php  --port=9999 --hostname=192.168.0.1;
  • --port=9999 = 9999 is an example port, but in this field you should write the same port number that you define on the Web client tab.
  • --hostname=192.168.0.1 = Must be the ip of the equipment that you wish the script run to kill transmission's process.

This makes me think that the process can be invoked remotely but for our particular case we are going to use the default values so that we need not to include neither the port nor the hostname. By simply running the script.php file in a terminal or invoked by transmission and it's going to use the default values which apply to our computer (localhost).

Then, let's cook fast food:

  1. We need a file, let's call it bye.sh and place it somewhere, your home folder is a good place for testing purposes.
  2. Insert the next inside of the file (fast food script here), save it, close it and give it execution permissions. (for reference, go down on this answer and find how).

enter image description here

  • Then, serve it inside of your Transmission "Download" tab but make sure you include the proper bye.sh file to be invoked when the download finishes.

enter image description here

That's it. I need to explain that somehow, the php script is succeeding but it observes a small delay after the downloads finishes and I have just tested with 2 small torrent files. I can't say if the delay will increase if the list is longer or the download size is heavier, behavior that is not observed by the New Recipe formula. However, the PHP file gives you the warranty that it's going to run in whatever OS that is PHP capable, and my New Recipe is mostly intended for Linux Based Systems, it works on Ubuntu and may succeed in other distributions, Debian or Ubuntu based, and certain modifications will allow it to succeed in other non Debian/Ubuntu based distributions.

Good luck!

New Recipe

OK I have a new recipe for this case, I admit it got all my attention, even when I don't use Transmission so often.

The Recipe

Ingredients

  1. transmission-gtk (installed somehow, from the software bag, terminal, etc.)
  2. transmission-cli (sudo apt-get install transmission-cli, provide password, wait the install to finish.)
  3. The Script. (cooked apart)

Preparation

  • Let's prepare our transmission in order to receive web client petitions from outside, this way we can monitor what is happening in our program. Let's open Transmission and go to the "Web" tab in order to enable the "Enable web client" checkbox as shown in the next screenshot.

enter image description here

(Default values will do the trick perfectly)

  • Let's open our favorite text editor in order to create a file named byebye.sh and let's place the next contents inside. (See the script here)

enter image description here

Now, let's find the bybye.sh file and give it the proper execution permissions by dropping in a terminal sudo chmod a+x bybye.sh or by entering the file properties in Nautilus and activating the "Allow executing file as program" checkbox in the "Permissions" as shown in the next screenshot.

enter image description here

  • Once we cooked out the script, let's install transmission-cli, in a terminal drop: sudo apt-get install transmission-cli, hit Enter and provide your password, after which the software will be installed.

Time for tasting

In a terminal, drop transmission-remote --list | sed '1d;$d' | grep -v Done | wc -l after which the results may vary from case to case, depending on the amount of torrents that are pending or currently downloading in transmission. If the results is different than 0 we're on our way. If you receive 0 and something is downloading or in queue, you must check the recipe from the beginning. If you receive an error please drop it in a comment in order to provide support.

  • If everything is going fine, now let's instruct transmission to run the script everytime a torrent is completed. CALM DOWN! Please, calm... the script will run each time a torrent is completely download, but it will only trigger the action to terminate transmission just when the results of downloads equals zero. This conditional way give us the tranquility that transmission won't close down on each download. A screenshot is provided for your convenience:

enter image description here

And voila! The recipe can be served in generous portions and in company of all your downloads. Transmission will close down just if the last download succeeded.

SOME WARNINGS

If Transmission is having only one pending action and the download finishes at the very moment of the software's opening, Transmission is going to close as soon as it opens.

Glossary:

killall -9 transmission = Will close transmission in a gently mode so that you won't receive an error message each time it is closed. By simply using killall transmission is going to close it in an rude way thus the software will report a close failure.

Now, make sure you include a glass with excellent Cuban rum for me in the table when serving the recipe and...

Good luck!

5
  • Ok I have added a new recipe with a workaround on how to solve your main problem, which I expect works without issues for you as it does for me. Both the PHP and the New Recipe solutions are working this side but somehow the New Recipe is doing a better work. I suggest you to try this new workaround and I am sure it is going to work. Please let me know if something is wrong and if you receive an error don't hesitate to drop it down right here to continue the support. Thank you very much. Apr 30, 2013 at 22:18
  • I have included an Addendum to the original php recipe in order to show how to include the php script in a sh file and allow transmission to execute it. I have also made the edition to the installation of php5-cli as you suggested and I am going to include my ticket in the pages that you suggested as soon as it is possible to me. I am going to consider improving the code after reading the post you suggest me but the codes that I have placed on the answer are working pretty fine, but if it can be improved be sure that I will do it. Thank you for the suggestions and observations. :) May 1, 2013 at 16:05
  • Doesn't it need to add Address:HTTPport between transmission-remote and --list according to web tab details? -however, I don't know anything about network :( Also I deleted my comments to make the answer more clear and clean. this comment will be removed soon, too.
    – mini
    May 3, 2013 at 20:32
  • Just if you change the default values. If you are using default values you can run it without any parameters, transmission-remote will assume you are using the proper default parameters and will return the proper results. I suggest you not to delete the comments because of my comments looks like a foolish monologue if your comments aren't there. :D Additionally, our comments will be useful for further visitors. Thank you! May 3, 2013 at 21:58
  • killall -9 transmission will not close transmission in "a gently mode", it'll kill it outright, leaving it no chance to clean up and save its state and configuration. To close it in a nice way, run transmission-remote --exit. Do NOT send it SIGKILL (-9). See stackoverflow.com/a/690631/347411
    – geirha
    Jul 21, 2013 at 12:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .