Ok after a bit of testing and research, I came up with this script that seems to be working
#!usr/bin/bash
# Define the directory where you want to start searching for rar files
start_directory="/root/of/torrent/download/folder/"
# Locate all rar files in subdirectories
find "$start_directory" -type f -name "*.rar" | while read rar_file; do
# Extract the rar file into the same directory, skip if it already exists
unrar x -o- "$rar_file" "$(dirname "$rar_file")"
echo "Extracted $rar_file to $(dirname "$rar_file")"
done
I chown'ed it to the qBittorrent user and gave it execute permissions. In qBittorrent I added the following to "Run external program on torrent finished"
bash /path/to/script.sh