Skip to content

Instantly share code, notes, and snippets.

@jfeilbach
Last active November 8, 2020 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfeilbach/7595cccd11fbc2653261924392b8968a to your computer and use it in GitHub Desktop.
Save jfeilbach/7595cccd11fbc2653261924392b8968a to your computer and use it in GitHub Desktop.
Search through <path>/*.torrent files for string $1. Passes two variables $(hash} and ${name} to rsync.sh script for migration.
#!/bin/bash
# Searches through directory of .torrent files for matchign string. If string found move to host, stop torrent, and add to new host.
# If you want to just move all .torrents then comment out "result" and uncomment the alternative version.
NC='\033[0m' # No color
Red='\033[0;31m' # Red
Green='\033[0;32m' # Green
Yellow='\033[0;33m' # Yellow
Blue='\033[0;34m' # Blue
Purple='\033[0;35m' # Purple
Cyan='\033[0;36m' # Cyan
White='\033[0;37m' # White
counter='1'
queue=/home/jason/queue
xfer=/home/jason/xfer
count=$(ls ${queue}/*.torrent | wc -l)
if [ "$1" == "" ]; then
echo -e "\n${Yellow}Please enter a search string. Exiting.${NC}\n"
exit 1
fi
if [ "${count}" == "0" ]; then
echo -e "\n${Red}Error: No .torrent files found. Exiting.${NC}\n"
exit 2
fi
search=$1
echo -e "\nSearching for ${White}"${search}"${NC}...\n"
for x in ${queue}/*.torrent ; do
result=$(/usr/bin/transmission-show ${x} | grep ${search})
# result=$(/usr/bin/transmission-show ${x})
if [[ -n "$result" ]] ; then
name=$(/usr/bin/transmission-show ${x} | grep 'Name: '| head -n 1 | sed 's/.*\:\ //' )
echo -e "\n${White}${search}${NC} found in ${Cyan}${x}${NC}.\n"
echo -e "\nTorrent is ${Cyan}${name}${NC}\n"
hash_part=${x%.*}
hash=${hash_part##*/}
echo $hash
cp -v ${x} ${xfer}/
echo -e "\nFound ${White}${counter}${NC} torrents to transfer so far.\n"
/home/jason/rsync.sh "${name}" "${hash}"
new_pid=$(echo $!)
wait ${new_pid}
(( counter++ ))
echo -e "\n${Green}Continuing search...${NC}\n"
fi
done
echo -e "\nFound a total of ${Cyan}${counter}${NC} torrents to be transferred. from ${search}\n"
exit 0
@jfeilbach
Copy link
Author

step 1 of 3 for migration

@jfeilbach
Copy link
Author

step 1 of 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment