Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # VARIABLES
  4. user="admin"
  5. password="admin"
  6. server="10.10.3.3"
  7. port="8080"
  8.  
  9.  
  10. # Don't change anything below this line (unless you know what you're doing)
  11. WGET_PARAMS_INITIAL="--save-cookies cookies.txt --keep-session-cookies"
  12. WGET_INITIAL="wget $WGET_PARAMS_INITIAL"
  13. WGET="wget --load-cookies cookies.txt"
  14.  
  15. # Get the auth token.
  16. resp1=`$WGET_INITIAL --http-user=$user --http-password=$password -q -O - http://$server:$port/gui/token.html`
  17.  
  18. token=`echo -e "$resp1" | awk -F'[<>]' '/<div[^>]*id=[\"'"'"']*token[\"'"'"'][^>]*>([^<]*)<\/div>/ { print $5 }'`
  19.  
  20. # Get the list of finished torrents
  21. resp2=`$WGET --http-user=$user --http-password=$password -q -O - http://$server:$port/gui/?list=1\&token=$token`
  22.  
  23. # Substring it to the start of the torrents list.
  24. ndx=`echo -e "$resp2" | tr "\n" " " | awk '{ndx=match($0, /,"torrents": \[/); print ndx }'`
  25. sstr=${resp2:ndx}
  26.  
  27. # Look at each line and identify the torrent listing.
  28. rx='^\[\"[^"]*\",[0-9]'
  29. IFS="
  30. "
  31.  
  32. #echo Processing Line: $sstr
  33. for line in $sstr
  34. do
  35. # If this line matches a torrent item in the torrents property...
  36. if [[ "$line" =~ $rx ]]; then
  37. # Tokenize the fields.
  38. lineTokens=(`echo -e "$line" | sed -e 's/\[//g;s/\]//g;s/"//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' `)
  39.  
  40. torrent=${lineTokens[2]}
  41. size=${lineTokens[3]}
  42. percent=${lineTokens[4]}
  43. downloaded=${lineTokens[5]}
  44.  
  45.  
  46. echo TORRENT: $torrent
  47. echo " SIZE: '$size'"
  48. echo " PERCENT: '$percent'"
  49. echo " DOWNLOADED: $downloaded"
  50.  
  51. # Double check that this is a torrent listing and that it's finished.
  52. if [[ "$percent" == "1000" ]]; then
  53. # Make the call to remove the torrent.
  54. TORRENT=${lineTokens[2]}
  55. removeAction="remove"
  56. resp3=`wget --load-cookies cookies.txt --http-user=$user --http-password=$password -q -O - http://$server:$port/gui/?action=$removeAction\&token=$token\&hash=${lineTokens[0]}`
  57. if [[ "$resp3" == "" ]]; then
  58. echo "Error removing torrent: ${lineTokens[2]} (id: ${lineTokens[0]})"
  59. fi
  60. fi
  61. fi
  62. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement