Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # script to check for complete torrents in transmission folder, then remove them and their associated files
- ###########
- # CONFIG #
- ###########
- # Access Information for Transmission
- USERNAME=admin
- PASSWORD=admin
- #SRC_DIR="${TR_TORRENT_DIR}/${TR_TORRENT_NAME}"
- #Installation directory of transmission
- INSTALLPATH="/volume1/@appstore/transmission"
- #Extra ratio check
- RATIO=3.0
- #Host on which transmission runs
- HOST=localhost
- #Port
- PORT=9091
- # use transmission-remote to get torrent list from transmission-remote list
- TORRENTLIST=`$INSTALLPATH/bin/transmission-remote $HOST:$PORT --auth=$USERNAME:$PASSWORD --list | awk '{print $1}' | grep '[0-9]'`
- # for each torrent in the list
- for TORRENTID in $TORRENTLIST
- do
- # check if torrent download is completed
- DL_COMPLETED=`$INSTALLPATH/bin/transmission-remote $HOST:$PORT --auth=$USERNAME:$PASSWORD --torrent $TORRENTID --info | grep "Percent Done: 100%"`
- # check torrents current state is "Stopped", "Finished", or "Idle"
- STATE_STOPPED=`$INSTALLPATH/bin/transmission-remote $HOST:$PORT --auth=$USERNAME:$PASSWORD --torrent $TORRENTID --info | grep "State: Stopped\|Finished\|Idle"`
- # get torrent name
- DL_NAME=`$INSTALLPATH/bin/transmission-remote $HOST:$PORT --auth=$USERNAME:$PASSWORD --torrent $TORRENTID --info | grep "Name: " | sed -e 's/ Name: //'`
- DL_PATH=`$INSTALLPATH/bin/transmission-remote $HOST:$PORT --auth=$USERNAME:$PASSWORD --torrent $TORRENTID --info | grep "Location: " | sed -e 's/ Location: //'`
- DL_RATIO=`$INSTALLPATH/bin/transmission-remote $HOST:$PORT --auth=$USERNAME:$PASSWORD --torrent $TORRENTID --info | grep "Ratio: " | sed -e 's/ Ratio: //'`
- # if the torrent is "Stopped", "Finished", or "Idle" after downloading 100%"
- echo "$DL_RATIO" -ge "$RATIO"
- if [ "$DL_COMPLETED" != "" ] && [ "$DL_RATIO" -ge "$RATIO" ]; then
- echo "Torrent $DL_NAME is completed."
- # remove torrent and data from Transmission
- echo "Removing torrent from list."
- $INSTALLPATH/bin/transmission-remote $HOST:$PORT --auth=$USERNAME:$PASSWORD --torrent $TORRENTID --remove-and-delete
- rm -R $DL_PATH/$DL_NAME
- else
- echo "Torrent $DL_NAME is not completed. Ignoring."
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment