#!/bin/sh NETRC=~/.netrc.transmission TR="transmission-remote -N $NETRC" # command + authentication FILE="lastrunning.list" # accepts arguments -sleep -wake if [ -z "$1" ]; then echo usage: $0 -sleep or -wake exit fi if [ "$1" = "-sleep" ]; then # save ID# of non-stopped torrents to array IDa=`$TR -l | grep -v Stopped | sed -e '1d' -e '$d' | awk '{print $1}'` # save unique hash# for non-stopped torrents instead of dynamic ID# for ID in $IDa; do $TR -t $ID -i | grep '^ Hash: ' | cut -c 9- >> $FILE done # pause all torrents $TR -t all --stop elif [ "$1" = "-wake" ]; then HASHa=($(cat $FILE)) for (( i=0;i<${#HASHa[@]};i++)); do $TR -t ${HASHa[${i}]} --start done rm $FILE # delete tempfile fi exit