I'm trying to create a bash script that is executed by Transmission when a torrent file is downloaded, and automatically extract *.rar files into the same directory.
This is what I have
#!/bin/bash
echo "------" >> /tmp/transmission.log
date >> /tmp/transmission.log
echo "$TR_TORRENT_DIR" >> /tmp/transmission.log
echo "$TR_TORRENT_NAME" >> /tmp/transmission.log
echo "Trying to extract: $TR_TORRENT_DIR/$TR_TORRENT_NAME" >> /tmp/transmission.log
find "$TR_TORRENT_DIR/$TR_TORRENT_NAME" -type d -maxdepth 1 -exec /usr/local/bin/bash -c 'cd "{}" && find . -name "*.rar" | xargs /usr/local/bin/7z x' \; &>> /tmp/transmission.log
The script is triggered, and everything looks fine, but there is no log output from the last line of the script, and the rar is never extracted. The script has chmod +x.
/tmp/transmission.log shows
------
Wed Feb 10 12:23:40 CET 2021
/Volumes/TV
My.File.720p.HDTV.x264-FILE
Trying to extract: /Volumes/TV/My.File.720p.HDTV.x264-FILE
What I've tried
If I manually set export TR_TORRENT_NAME=... and export TR_TORRENT_DIR=... in Terminal and run the command from the last line of the script, then the file is actually extracted properly.
What could be going on here? How can I debug this issue further?