Script to cleanup unrar'd files after torrent automatically removed
Many torrent releases on private trackers are still in a .rar archive. For automation these need to be extracted. In qBitTorrent this can be done by using the external program with a command such as:
unrar x "%F/.r" "%F/"
When using a cleanup to automatically remove torrents, wether that be natively in qBitTorrent or using a script such as autoremove-torrents the UnRAR'd file and subsequently the sub folder are not removed.
If you're using other tools such as Sonarr, Radarr, Lidarr, etc...which automatically copy your files, and the extracted files are left in a temporary location then this isnt ideal.
This script will scrub the qBitTorrent log and delete leftover files.
New Script Install qbittorrent-cli Install jq (JSON processor)
sudo apt update && sudo apt install -y jq
Clone qBitTorrent-Cleanup
git clone https://github.com/Jarsky/qBitTorrent-Cleanup-Script.git && chmod +x ./qBitTorrent-Cleanup-Script/qBitTorrent-Cleanup.sh
Configure defaults for qbittorrent-cli
qbt settings set url http://localhost:8000 #URL of qBitTorrent WebUI
qbt settings set username <username> #Only if you enabled user authentication
qbt settings set password <prompt> #Only if you enabled user authentication
Edit the path to your downloads and qbittorrent.log in the script
./qBitTorrent-Cleanup.sh --help
for supported commands
./qBitTorrent-Cleanup.sh -legacy test
for log only (no deletion)
./qBitTorrent-Cleanup.sh -legacy
qBt-mover can setup CRON for you.
Simply run ./qBitTorrent-Cleanup.sh -cron
which will give you the commands.
Setting up the default using ./qBitTorrent-Cleanup.sh -cron legacy looks like below
## qBitTorrent-Cleanup cron
* 4 * * * cd /home/jarsky/scripts/qBitTorrent-Cleanup-Script && ./qBitTorrent-Cleanup.sh -legacy
If you want to remove the CRON entries just use
./qBitTorrent-Cleanup.sh -cron remove
Default: /var/log/qBitTorrent-Cleanup.log
If you want to run the script as your user in this location, then:
sudo touch /var/log/qBitTorrent-Cleanup.log
sudo chmod 755 /var/log/qBitTorrent-Cleanup.log
It is good practice to configure a logrotate.
In most GNU you would do something like this
sudo touch /etc/logrotate.d/qBitTorrent-Cleanup
sudo nano /etc/logrotate.d/qBitTorrent-Cleanup
And put the below code into the file and save
/var/log/qBitTorrent-Cleanup.log {
size 20M
rotate 5
compress
delaycompress
missingok
notifempty
}
NOTE You should set a larger size, as the script relies on the log for legacy function
This will let the log grow to 20 Megabytes, then rotate.
It will rotate 5x and then delete the oldest.
The log files from 2 onwards will be compressed.
You can run do a dry-run by running this command
sudo logrotate -d /etc/logrotate.d/qBitTorrent-Cleanup