![移动或解压文件的脚本(rtorrent 完成脚本时)](https://linux22.com/image/1520257/%E7%A7%BB%E5%8A%A8%E6%88%96%E8%A7%A3%E5%8E%8B%E6%96%87%E4%BB%B6%E7%9A%84%E8%84%9A%E6%9C%AC%EF%BC%88rtorrent%20%E5%AE%8C%E6%88%90%E8%84%9A%E6%9C%AC%E6%97%B6%EF%BC%89.png)
这个概念
因此,我一直在苦苦思索一个脚本,该脚本将在 rtorrent 完成下载后运行。该脚本应检查 rtorrent 的第三个参数并采取相应措施。
.rtorrent.rc:
system.method.set_key = event.download.finished,unrar_move_files,"execute={/home/holmen/script/testrt.sh,$d.get_base_path=,$d.get_name=,$d.get_custom1=}"
脚本如下:
#!/bin/bash
# First, copy the downloaded material to the storage drive
# then unpack the files (if the unrar returned successful)
# lastly remove the rar files with rm -rfv command
hdfilm1=/media/store1/HD-film
hdfilm2=/media/store2/HD-film
download=/media/store3/Download
# Copy the downloaded material to correct storage drive
rsync -r --info=progress2 "$download"/"$2" "$3"
if [ "$3" = "$hdfilm1" ] || [ "$3" = "$hdfilm2" ]; then
# Check folders and subfolders of the downloaded material
while IFS= read -r dir; do
# Find and unpack archive files
if [ "$(find $dir | egrep -i '\.r00|\.001|part01\.rar|part001\.rar|subs\.rar')" ]; then
rarFile=`ls $dir | egrep -i '\.r00|\.001|part01\.rar|part001\.rar|subs\.rar'`;
searchPath="$dir/$rarFile"
yes no | nice -n 15 unrar x -o+ "$searchPath" "$dir"
remFile=`ls $dir | egrep -i '\.(rar|sfv|r([0-9]{2}))$'`;
remPath="$dir/$remFile"
rm -rfv $remPath
fi
done < <(find "$3"/"$2" -type d)
fi
这基本上可行,但我在尝试删除存档文件(解压后)时遇到了麻烦。在循环中添加删除脚本时,while
该脚本只会删除当前所在的特定子文件夹中的文件。
脚本解压如下:
/media/store1/HD-film/Movie.folder/*.rar
/media/store1/HD-film/Movie.folder/Subs/*.rar
但只删除此文件夹中的 rar 文件
/media/store1/HD-film/Movie.folder/Subs/
我该如何修复,以便我的脚本也删除父文件夹中的存档文件?
编辑:我尝试将该rm
命令放在 unrar 命令后面,&&
但结果是一样的。
if [ "$(find $dir | egrep -i '\.r00|\.001|part01\.rar|part001\.rar|subs\.rar')" ]; then
rarFile=`ls $dir | egrep -i '\.r00|\.001|part01\.rar|part001\.rar|subs\.rar'`;
searchPath="$dir/$rarFile"
remFile=`ls $dir | egrep -i '\.(rar|sfv|r([0-9]{2}))$'`;
remove="$dir/$remFile"
yes no | nice -n 15 unrar x -o+ "$searchPath" "$dir" && rm -rfv "$remove"
fi
答案1
我已经找到了解决此脚本问题的方法未拉拉尔。我已经在我的脚本中实现了它。
#!/bin/bash
# Variables
hdfilm1=/media/store1/HD-film
hdfilm2=/media/store2/HD-film
tvshow1=/media/store0/Serier
tvshow2=/media/store2/Serier
download=/media/store3/Download
# Copy the downloaded material to correct storage drive
rsync -r --info=progress2 "$download"/"$2" "$3"
if [ "$3" = "$hdfilm1" ] || [ "$3" = "$hdfilm2" ] || [ "$3" = "$tvshow1" ] || [ "$3" = "$tvshow2" ]; then
/home/holmen/script/unrarall --clean=rar,proof_folders,sample_folders,sample_videos,empty_folders "$3"/"$2"
fi