Guest User

Untitled

a guest
Feb 27th, 2014
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # script to check for complete torrents in transmission folder, then remove them and their associated files
  4.  
  5. ###########
  6. # CONFIG #
  7. ###########
  8. # Access Information for Transmission
  9. USERNAME=admin
  10. PASSWORD=admin
  11. #SRC_DIR="${TR_TORRENT_DIR}/${TR_TORRENT_NAME}"
  12. #Installation directory of transmission
  13. INSTALLPATH="/volume1/@appstore/transmission"
  14. #Extra ratio check
  15. RATIO=3.0
  16. #Host on which transmission runs
  17. HOST=localhost
  18. #Port
  19. PORT=9091
  20.  
  21. # use transmission-remote to get torrent list from transmission-remote list
  22. TORRENTLIST=`$INSTALLPATH/bin/transmission-remote $HOST:$PORT --auth=$USERNAME:$PASSWORD --list | awk '{print $1}' | grep '[0-9]'`
  23. # for each torrent in the list
  24. for TORRENTID in $TORRENTLIST
  25.  
  26. do
  27. # check if torrent download is completed
  28. DL_COMPLETED=`$INSTALLPATH/bin/transmission-remote $HOST:$PORT --auth=$USERNAME:$PASSWORD --torrent $TORRENTID --info | grep "Percent Done: 100%"`
  29.  
  30. # check torrents current state is "Stopped", "Finished", or "Idle"
  31. STATE_STOPPED=`$INSTALLPATH/bin/transmission-remote $HOST:$PORT --auth=$USERNAME:$PASSWORD --torrent $TORRENTID --info | grep "State: Stopped\|Finished\|Idle"`
  32.  
  33. # get torrent name
  34. DL_NAME=`$INSTALLPATH/bin/transmission-remote $HOST:$PORT --auth=$USERNAME:$PASSWORD --torrent $TORRENTID --info | grep "Name: " | sed -e 's/ Name: //'`
  35. DL_PATH=`$INSTALLPATH/bin/transmission-remote $HOST:$PORT --auth=$USERNAME:$PASSWORD --torrent $TORRENTID --info | grep "Location: " | sed -e 's/ Location: //'`
  36. DL_RATIO=`$INSTALLPATH/bin/transmission-remote $HOST:$PORT --auth=$USERNAME:$PASSWORD --torrent $TORRENTID --info | grep "Ratio: " | sed -e 's/ Ratio: //'`
  37.  
  38. # if the torrent is "Stopped", "Finished", or "Idle" after downloading 100%"
  39. echo "$DL_RATIO" -ge "$RATIO"
  40. if [ "$DL_COMPLETED" != "" ] && [ "$DL_RATIO" -ge "$RATIO" ]; then
  41. echo "Torrent $DL_NAME is completed."
  42. # remove torrent and data from Transmission
  43. echo "Removing torrent from list."
  44. $INSTALLPATH/bin/transmission-remote $HOST:$PORT --auth=$USERNAME:$PASSWORD --torrent $TORRENTID --remove-and-delete
  45. rm -R $DL_PATH/$DL_NAME
  46. else
  47. echo "Torrent $DL_NAME is not completed. Ignoring."
  48. fi
  49.  
  50. done
Advertisement
Add Comment
Please, Sign In to add comment