Copy Completed Torrents

Suggestions and discussion of future versions
Sentinel
Member
Member
Posts: 21
Joined: Sun Oct 26, 2008 10:41 pm

Re: Copy Completed Torrents

Post by Sentinel »

Code: Select all

#!/bin/bash

# Assumes that newly-finished torrent files are automatically
# moved to the SEEDING directory

# directory of finished torrents that are seeding
SEEDING=/mnt/Vault/Seeding/

# blacklist
BLACKLIST=/mnt/Vault/Finished/blacklist.txt

# where to move files for archival staging
# files can be edited and removed from this folder
# whithout affecting seeding copy
FINISHED=/mnt/Vault/Finished/

# for each file or folder in the SEEDING directory,
# check if it's on the blacklist
# if it is not, then recursively copy it to FINSIHED
# and add it to the blacklist
cd $SEEDING
echo Copying files from Seeding directory to Finished Directory...
for file in *
do
  COUNT=`grep -cF "$file" $BLACKLIST`
  if [ $COUNT == 0 ]; then
    echo $file
    cp -r "$file" $FINISHED
    echo "$file" >> $BLACKLIST
  fi
done
I found that adding quotes around $file like "$file" fixed the problem where a file name had more than one space in a row. Now the file name is correctly added to the blacklist, so grep matches it correctly. See my corrected script above.
Post Reply