summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshymad <czilukim@o2.pl>2018-08-17 19:05:18 +0200
committerAshymad <czilukim@o2.pl>2018-08-17 19:06:26 +0200
commita8681eb1b0571d36608649a5d9409fe20859b3a0 (patch)
tree1a8f0e59f2d5c6074231ad57534044a529435daf
parent49120a060defbcdb8222d21a09dc126ba89a88a2 (diff)
Update to new syntax; remove expr
-rwxr-xr-xrTorrent_delete_old_stopped/liststopped.sh38
1 files changed, 21 insertions, 17 deletions
diff --git a/rTorrent_delete_old_stopped/liststopped.sh b/rTorrent_delete_old_stopped/liststopped.sh
index 001d650..6969d17 100755
--- a/rTorrent_delete_old_stopped/liststopped.sh
+++ b/rTorrent_delete_old_stopped/liststopped.sh
@@ -1,28 +1,32 @@
#!/bin/bash
# This scripts lists torrents from rtorrent that are currently stopped and gets path and name of the files.
# Then deletes files that are older than $AGE.
-AGE=1814400 # 3 weeks
+set -e
+
+AGE=1209600 # 2 weeks
# Before using set username and password with your server access control credentials.
USERNAME=
PASSWORD=
+# Path to xmlrpc binary
+XMLRPC="/usr/local/bin/xmlrpc"
# Desinged to run at schedule (crontab).
-HSHARR=( $( xmlrpc -a $USERNAME:$PASSWORD https://localhost/RPC2 d.multicall -s stopped -s d.get_hash= | xmllint --xpath "string(//value)" - | awk 'NF > 0' ) )
+HSHARR=( $( $XMLRPC -a $USERNAME:$PASSWORD https://localhost/RPC2 d.multicall2 -s "" -s stopped -s d.hash= | xmllint --xpath "string(//value)" - | awk 'NF > 0' ) )
for HSH in "${HSHARR[@]}"; do
- DIR=$( xmlrpc -a $USERNAME:$PASSWORD https://localhost/RPC2 d.get_directory -s $HSH | xmllint --xpath "string(//string)" - )
- COUNT=$( xmlrpc -a $USERNAME:$PASSWORD https://localhost/RPC2 d.get_size_files -s $HSH | xmllint --xpath "string(//i8)" - )
- COUNT=$( expr $COUNT - 1 )
- for IDX in $( seq 0 $COUNT ); do
- FILE=$( xmlrpc -a $USERNAME:$PASSWORD https://localhost/RPC2 f.get_path -s $HSH -i $IDX | xmllint --xpath "string(//string)" - )
- F_PATH="$DIR/$FILE"
- if (( $IDX==0 && $( expr $( date +%s ) - $( date +%s -r "$F_PATH" ) ) < $AGE )); then
- break
- fi
- rm "$F_PATH"
- rmdir --ignore-fail-on-non-empty -p "${F_PATH%/*}"
- if (( $IDX==$COUNT )); then
- xmlrpc -a $USERNAME:$PASSWORD https://localhost/RPC2 d.erase -s $HSH
- fi
- done
+ DIR=$( $XMLRPC -a $USERNAME:$PASSWORD https://localhost/RPC2 d.directory -s $HSH | xmllint --xpath "string(//string)" - )
+ COUNT=$( $XMLRPC -a $USERNAME:$PASSWORD https://localhost/RPC2 d.size_files -s $HSH | xmllint --xpath "string(//i8)" - )
+ COUNT=$(( $COUNT - 1 ))
+ for IDX in $( seq 0 $COUNT ); do
+ FILE=$( $XMLRPC -a $USERNAME:$PASSWORD https://localhost/RPC2 f.path -s "$HSH:f$IDX" | xmllint --xpath "string(//string)" - )
+ F_PATH="$DIR/$FILE"
+ if (( $IDX==0 && $(( $( date +%s ) - $( date +%s -r "$F_PATH" ) )) < $AGE )); then
+ break
+ fi
+ rm "$F_PATH"
+ rmdir --ignore-fail-on-non-empty -p "${F_PATH%/*}"
+ if (( $IDX==$COUNT )); then
+ $XMLRPC -a $USERNAME:$PASSWORD https://localhost/RPC2 d.erase -s $HSH
+ fi
+ done
done