I would like to run batch script on my transmission docker. The script, should starts just after the torrent is downloaded. I receive following error:
sh transmission-post-stop2.sh
: not foundn-post-stop2.sh: line 2:
: not foundn-post-stop2.sh: line 13:
: not foundn-post-stop2.sh: line 16:
transmission-post-stop2.sh: line 18: syntax error: unexpected "("
My code is following:
#!/bin/bash
# Clears finished downloads from Transmission.
SERVER="127.0.0.1:9001 --auth xyz:xyz"
DONE_STATES=("Seeding" "Stopped" "Finished" "Idle")
if [[ -n "$TRANSMISSION_SERVER" ]]; then
echo -n "Using server string from the environment: "
SERVER="$TRANSMISSION_SERVER"
elif [[ "$#" -gt 0 ]]; then
echo -n "Using server string passed through parameters: "
SERVER="$*"
else
echo -n "Using hardcoded server string: "
fi
echo "${SERVER: : 10}(...)" # Truncate to not print auth.
TORRENT_LIST=$(transmission-remote $SERVER --list | sed -e '1d' -e '$d' | awk '{print $1}' | sed -e 's/[^0-9]*//g')
for TORRENT_ID in $TORRENT_LIST
do
INFO=$(transmission-remote $SERVER --torrent "$TORRENT_ID" --info)
echo -e "Processing #$TORRENT_ID: \"$(echo "$INFO" | sed -n 's/.*Name: \(.*\)/\1/p')\"..."
# To see the full torrent info, uncomment the following line.
# echo "$INFO"
PROGRESS=$(echo "$INFO" | sed -n 's/.*Percent Done: \(.*\)%.*/\1/p')
STATE=$(echo "$INFO" | sed -n 's/.*State: \(.*\)/\1/p')
# If the torrent is 100% done and the state is one of the done states.
if [[ "$PROGRESS" == "100" ]] && [[ "${DONE_STATES[@]}" =~ "$STATE" ]]; then
echo "Torrent #$TORRENT_ID is done. Removing torrent from list."
transmission-remote $SERVER --torrent "$TORRENT_ID" --remove
else
echo "Torrent #$TORRENT_ID is $PROGRESS% done with state \"$STATE\". Ignoring."
fi
done
I'll be very grateful for any help.