0

The concept

So I´ve been struggling for a while now with a script that will run when rtorrent has finished a download. The script should check the third argument from rtorrent and act accordingly.

.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=}"

The script looks like this:

#!/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

This works basically but i have trouble when trying to delete the archive files (after they are unpacked). When adding a remove script in the while loop the script just removes files in the specific subfolder its in at the moment.

The script unpacks:

/media/store1/HD-film/Movie.folder/*.rar
/media/store1/HD-film/Movie.folder/Subs/*.rar

but only removes the rar files in this folder

/media/store1/HD-film/Movie.folder/Subs/

How can I fix so my script removes the archive files also in the parent folder?

Edit: I have tried putting the rm command after the unrar command with && but the result is the same.

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
4
  • How do you try to remove rar files? It would be better to include that in the posted code. – janos Jan 29 '17 at 21:45
  • I added this code to the if section of the while loop: remFile=` ls $dir | egrep -i '\.[r|s|0-9][a|f|0-9][r|v|0-9]$'`; remPath="$dir/$remFile"; rm -rfv $remPath – junkyhlm Jan 29 '17 at 21:58
  • It would be better to edit that into your question – janos Jan 29 '17 at 22:23
  • I have edited my question – junkyhlm Jan 29 '17 at 23:01
0

I've found a solution for my problem with this script unrarall. I've implemented it in my script.

#!/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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.