Skip to content

Instantly share code, notes, and snippets.

@Luismcplopes
Last active January 17, 2023 00:27
Show Gist options
  • Save Luismcplopes/09182033ccfa99fccde0f7a6ae281cd6 to your computer and use it in GitHub Desktop.
Save Luismcplopes/09182033ccfa99fccde0f7a6ae281cd6 to your computer and use it in GitHub Desktop.
Transmission-Daemon: Remove or/and Move Completed Torrents
#!/bin/sh
# https://community.wd.com/t/guide-auto-removal-of-downloads-from-transmission-2-82/93156
# script to check for complete torrents in transmission folder, then stop and move them
# either hard-code the MOVEDIR variable here…
# MOVEDIR=/home/amhiserver/.box # the folder to move completed downloads to
# …or set MOVEDIR using the first command-line argument
# MOVEDIR=%1
#
# auth
# port, username, password
# SERVER="localhost:9091 --auth osmc:osmc"
# transmission-remote $SERVER --list
#
# use sed to delete first / last line of output, and remove leading spaces
# use cut to get first field from each line
TORRENTLIST=$(transmission-remote --list | sed -e '1d;$d;s/^ *//' | cut --only-delimited --delimiter=" " --fields=1)
# for each torrent in the list
for TORRENTID in $TORRENTLIST
do
TORRENTID=$(echo "$TORRENTID" | sed -e 's:*::')
# removes asterisk * from torrent ID# which had error associated with it
echo "$TORRENTID"
# check if torrent download is completed
DL_COMPLETED=$(transmission-remote --torrent "$TORRENTID" --info | grep "Percent Done: 100%")
echo "$DL_COMPLETED"
# check torrent's current state is "Stopped", "Finished", or "Idle"
STATE_STOPPED=$(transmission-remote --torrent "$TORRENTID" --info | grep "State: Stopped\|Finished\|Idle")
#(transmission-remote --torrent 1 --info | grep "Error: No data found! Ensure your drives are connected")
echo "$STATE_STOPPED"
# if the torrent is "Stopped", "Finished", or "Idle" after downloading 100%…
if [ "$DL_COMPLETED" != "" ] && [ "$STATE_STOPPED" != "" ]; then
# move the files and remove the torrent from Transmission
# echo "Torrent #$TORRENTID is completed."
# echo "Moving downloaded file(s) to $MOVEDIR."
#transmission-remote --torrent $TORRENTID --move $MOVEDIR
echo "Removing torrent from list."
transmission-remote --torrent "$TORRENTID" --remove
else
echo "Torrent #$TORRENTID is not completed. Ignoring."
fi
echo "* * * * * Operations on torrent ID $TORRENTID completed. * * * * *"
done
slack_url=`cat //usr/bin/slack_url`
start_text="Cleanup Transmission \n Ongoing \n`transmission-remote --list | sed 's/\s\+/#/g' | cut -d"#" --complement -s -f1-10 --output-delimiter=" "`"
# start_text+=\n teste
curl -H "Content-type:application/json" \
-X POST -d \
'{
"channel":"#ll-osmc",
"username" : "Transmission",
"icon_emoji" : ":transmission:",
"text" : "'"$start_text"'",
}
' $slack_url
exit 0
@Luismcplopes
Copy link
Author

Luismcplopes commented Feb 28, 2019

Script to CleanUP Transmission

For this to run automatic is need to edit a cron job

Runnig from CronJob

crontab not working in OSMC

Don’t forget to make it executable : sudo chmod +x /home/osmc/removecompletedtorrents.sh
Then schedule the job with cron :
crontab -e
append this line at the end of the file, the script will run every 12 Hours with no output at all.
0 */12 * * * /home/osmc/removecompletedtorrents.sh > /dev/null 2>&1
0 */12 * * * /home/osmc/removecompletedtorrents.sh >> /dev/null 2>&1

if you want some output (to see which files have been deleted)
0 */12 * * * /home/osmc/removecompletedtorrents.sh > /path/to/outputFile
0 */12 * * * /home/osmc/removecompletedtorrents.sh >> /path/to/outputFile

Restart as 4:30 AM

30 4 * * * sudo /sbin/shutdown -r

Runnig from Transmission

https://www.htpcguides.com/make-transmission-automatically-stop-seeding-complete/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment