Background
The focus of this post is on a Tranmission application deployed as a docker container on an Unraid server. However, a similar workflow can be followed on other systems with minor modification of the script. The goal of the script is to remove any unregistered torrents in Transmission to avoid doing the process manually and reclaim storage space. Unregistered torrents are those that are removed from the upstream service either due to errors or being trumped by new additions. The script parameters are based on the documentation found at Linux tranmission-remote cli.
Prerequisites
- Terminal access to the Unraid server
- Log into the GUI and hit the terminal button to validate proper functionality
- User Scripts Unraid plugin
- Go to APPS and download if not present
- Determine the location of the appdata folder of the Tranmission docker on your system
- Default location:
/mnt/user/appdata/transmission
- Default location:
Adding the Script
To add the script to the system, we have to keep in mind the distinction between the Unraid server files system and the docker container.
As stated earlier, the default location of the docker on the Unraid server is /mnt/user/appdata/transmission which on the docker container translates to /config. At a high level, we will add the script below to the Unraid server and use the User Scripts to call the script on the physical machine at a specified interval. The script will execute within the docker environment with the Unraid server only as a script maintainer. The benefit of this method is that you will retain visibility from your main Unraid server without having to interact with the docker container afterwards. With all that out of the way, lets get started!!
- Log into the Unraid web GUI and open the terminal by clicking on the terminal button on the top right
- Change into the tranmission folder:
cd /mnt/user/appdata/transmission - Add the following script modifying the username and password. This is a temporary script that only lists the files before the final change is implemented:
nano delete_unregister.sh
#!/bin/bash TRANSMISSION_USER="admin" TRANSMISSION_PASSWORD="password" # Connects to the transmission client and retrieves a list of the torrents that are unregistered UNREGISTERED_TORRENTS=$(transmission-remote --auth "$TRANSMISSION_USER:$TRANSMISSION_PASSWORD" -tall -i | grep -E -B20 -i "unregistered|error: complete|other: see|problem with file|dupe|does not exist" | grep -i "id:" | tr -d [:blank:][Id:] | tr "\n" "," | sed 's/.$//') UNREGISTERED_TORRENTS_NAME=$(transmission-remote --auth "$TRANSMISSION_USER:$TRANSMISSION_PASSWORD" -t "$UNREGISTERED_TORRENTS" -l) if [ -z "$UNREGISTERED_TORRENTS" ]; then # If no unregistered torrents are found, the timestamp is written to the log file echo "[$(date +'%Y-%m-%d %H:%M:%S')] None present" >> /config/unregister.log exit 0 else # If registered torrents are found, each individual torrent is written to the log file and then deleted from the list as well as removed from the drive echo "[$(date +'%Y-%m-%d %H:%M:%S')] Deleting unregistered torrents: $UNREGISTERED_TORRENTS_NAME" >> /config/unregister.log transmission-remote --auth "$TRANSMISSION_USER:$TRANSMISSION_PASSWORD" -t "$UNREGISTERED_TORRENTS" --list fi - Make the script executable with:
chmod +x delete_unregister.sh
Validate the script
- Go into the Tranmission GUI and validate whether there are any Unregistered torrents present
- From the web GUI go to DOCKER tab and left click on the Transmission docker, select Console
- Execute the script and validate the output matches the expected behavior:
/config/delete_unregister.sh
cat /config/unregister.log - If the output is correct, either “None present” or the torrent is listed, the script is working as expected.
- Replace the
--listwith--remove-and-delete
Scheduling the script from Unraid
Unraid will be used to execute a script within the docker container using “docker exec” and then the log will be read to retain the history of the changes of the system.
- Open the User Scripts from PLUGINS tab within Unraid
- Select “ADD NEW SCRIPT” at the bottom of the page and add relevant name, ex. delete unregistered
- Find the script in the list, click the gear icon, and then click “EDIT SCRIPT”
- Paste the following script making the proper changes to the appdata folder:
#!/bin/bash
docker exec transmission /config/delete_unregister.sh
cat /mnt/user/appdata/transmission/unregister.log - Click the “SAVE CHANGES”
- Change the “Schedule Disabled” to a desired schedule and then hit “Apply” at the bottom of the page.
- Validate the script can execute from Unraid by clicking the “RUN SCRIPT”