我编写了一个脚本,该脚本将从 Dropbox 获取 torrent 文件,将它们添加到传输并将 torrent 移动到另一个位置。该脚本对我有用,只要我一次只将一个文件放在一个文件夹中。如果文件夹中有多个文件,它会给我一个关于文件路径太长的错误。谁能从我的脚本下面告诉我我做错了什么以及如何更改它以便它可以正确处理多个文件?这是 Mac 上的一个 bash 脚本,通过 launchd 每 60 秒执行一次。
谢谢!
#!/bin/bash
# Log to debug file
set –xv; exec 1>>/Users/admin/TorrentMoverLog.txt 2>&1
date
###################################################
### ###
### Torrent Mover v.0.1 ###
### ###
###################################################
################# Variables #####################
###################################################
######## Watch Folders ##
## ##
WATCH_PATH=/Users/admin/Dropbox/Torrent-Drop/
WATCH_FOLDERS=( Movies/ TV/ Music/ FLAC/ Software/ Other/ )
## ##
######## DL Folders ##
## ##
DL_PATH=/Volumes/Media/
## ##
###################################################
################ Functions ######################
###################################################
## ##
function add_torrent {
/usr/local/bin/transmission-remote -a "$1" -w "$2""$3"
}
## ##
###################################################
################### Script ######################
## ##
## Rename files with spaces
echo "Renaming files with spaces"
find "$WATCH_PATH" -depth -name "* *" -execdir rename 's/ /_/g' "{}" \;
## Start Outer Loop
## Process Watch Folders
for wf in "${WATCH_FOLDERS[@]}"
do
WF_LIST=`ls $WATCH_PATH${wf} | grep torrent`
## Check for torrent files first, skip if none found
if [ "$WF_LIST" != "" ]; then
echo "Processing ${wf} folder..."
## Start Inner Loop
## Process Files within watch folders
## Set download folder
for torrent in "$WF_LIST";
do
case "${wf}" in
Movies/ ) echo "Movies variable set"
DL_FOLDER=Movies/ ;;
TV/ ) echo "TV variable set"
DL_FOLDER=TV_Shows/ ;;
Music/ ) echo "Music variable set"
DL_FOLDER=Music/ ;;
FLAC/ ) echo "FLAC variable set"
DL_FOLDER=PlexMusic/ ;;
Software/ ) echo "Software variable set"
DL_FOLDER=Software/ ;;
Other/ ) echo "Other variable set"
DL_FOLDER=Other/ ;;
esac
## Add torrent to transmission
echo "Running command, add_torrent $WATCH_PATH${wf}$torrent $DL_PATH $DL_FOLDER"
add_torrent "$WATCH_PATH${wf}$torrent" "$DL_PATH" "$DL_FOLDER"
## Move torrent
echo "Moving $WATCH_PATH${wf}$torrent to $DL_PATH""TorrentFiles/"
mv "$WATCH_PATH${wf}$torrent" "$DL_PATH""TorrentFiles/"
done
## End Inner Loop
echo "Finished processing torrents in ${wf} folder."
else
echo "Skipping ${wf} directory, no torrents found."
fi
done
## End Outer Loop
exit 0