Skip to content

Instantly share code, notes, and snippets.

@ahornerr
Created July 19, 2015 23:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahornerr/af83d539fb034411f53d to your computer and use it in GitHub Desktop.
Save ahornerr/af83d539fb034411f53d to your computer and use it in GitHub Desktop.
#!/bin/bash
LOG_FILE=/var/lib/transmission-daemon/posttorrent.log
# Username for transmission remote.
TR_USERNAME="transmission"
# Password for transmission remote.
TR_PASSWORD=""
# Get current time.
NOW=$(date +%Y-%m-%d\ %H:%M:%S)
DEST_DIR="/media/raid/Processed Torrents/"
echo $NOW "===Source: ${TR_TORRENT_DIR} ${TR_TORRENT_NAME}===" >> $LOG_FILE
cd "$TR_TORRENT_DIR" &>> $LOG_FILE
pwd &>> $LOG_FILE
if [ -d "$TR_TORRENT_NAME" ]; then
find "$TR_TORRENT_NAME" -iname "*.rar" | while read file
do
echo $NOW "Unrarred $file" >> $LOG_FILE
unrar x -inul "$file"
done
find "$TR_TORRENT_NAME" -iname "*.zip" | while read file
do
echo $NOW "Unzipped $file" >> $LOG_FILE
unzip "$file"
done
fi
mkdir -p "$DEST_DIR"
echo $NOW "Executing the following command: 'cp -R \"$TR_TORRENT_DIR/$TR_TORRENT_NAME\" \"$DEST_DIR\"'" >> $LOG_FILE
cp -r "$TR_TORRENT_DIR/$TR_TORRENT_NAME" "$DEST_DIR" # &>> $LOG_FILE
copy_retval=$?
if [$copy_retval -ne 0]; then
echo $NOW "Error copying torrent to output directory: $copy_retval" >> $LOG_FILE
else
chmod -R 777 "$DEST_DIR" #&>> $LOG_FILE
echo $NOW "Moved \"$TR_TORRENT_NAME\" to \"$DEST_DIR\"" >> $LOG_FILE
transmission-remote -n $TR_USERNAME:$TR_PASSWORD -t $TR_TORRENT_ID --remove-and-delete # >> $LOG_FILE
# echo $NOW "Removed torrent ${TR_TORRENT_NAME} with id ${TR_TORRENT_ID} from transmission" >> $LOG_FILE
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment