Hi there,
This post is going to show you how to enable a feature of transmission, which can run a script after a torrent was completed successfully. This may be usefull when you want to move the files to a share, or allow someone using a share to modify the downloaded files without any knowledge of the debian-transmission user and password.
In order to configure this we have to stop the transmission daemon with the following command.
/etc/init.d/transmission-daemon stop
After this I have created a folder called scripts to my root folder with the following command.
mkdir ~/Scripts
Then created the script which has to be run after each completed download.
touch ~/Scripts/AfterDL.sh
I have given it the right to be executable with this command.
chmod +x ~/Scripts/AfterDL.sh
Added these lines into the file.
#!/bin/bash
filename=$(transmission-remote -n <username>:<password> `
–list |grep Idle | `
awk ‘{ for(i=10; i<NF; i++) printf “%s”,$i OFS; if(NF) printf “%s”,$NF; printf ORS}’)
fullpath=/home/pi/Downloads/$filename
sudo chgrp -R pi “$fullpath”
sudo chown -R pi “$fullpath”
The first line tells the interpreter to use Bourne Again Shell, The second line retrieves the finished torrents name from the cli of transmission. The third line creates the full path to the file. The fourth line is changing the group of the file recursively in case its a directory, the last line changes the owner of the file.
There are only 2 things to do before we can say start using it. The first is to modify the owner and group of the AfterDL.sh script so that debian-transmission can use it.
chown debian-transmission ~/Scripts/AfterDL.sh
chgrp debian-transmission ~/Scrtips/AfterDL.sh
The last thing of course is to modify the settings file of transmission. This is located here.
/etc/transmission-daemon/settings.json
In here there are only 2 lines to be modified.
“script-torrent-done-enabled”: true,
“script-torrent-done-filename”: “/home/pi/Scripts/AfterDL.sh”,
The first line specifies the status of it, the second is the location of the scritps. There maybe cases when debian-transmission has no rights to use the “sudo”command and this can be worked around by editing the /etc/sudoers file adding the following.
debian-transmission ALL=(ALL) NOPASSWD: ALL
Now all we have to do is start the daemon.
/etc/init.d/transmission-daemon start
Once our newly added torrent finishes it will be visible that the owner and group has changed by issuing the “ls -l” command in our Downloads directory.
I hope this has been informative to you 🙂
Cheers,
Daniel