SABnzbd Disk Monitor Script

Many of you who followed this guide are probably using a VPS provider which offers a little less disk space than you’d hope. Here’s my method to keep things running smoothly while allowing enough disk space for Plex to transcode and keep your downloads going. This script will

You’ll want to replace ‘/dev/md2’ with your primary disk to which SABnzbd downloads, and ‘YOURAPIKEYHERE’ with your SABnzbd API key. You can also adjust ‘-lt 100’ with the number of GBs free on your disk at which you’d like your downloads to resume.

To get this script to run, first go into your SABnzbd settings and look under the ‘Folders’ section. You’ll see an option labeled ‘Minimum Free Space for Temporary Download Folder’ where you can enter the lower limit of space where you want SABnzbd to pause downloads. I use 70G so I know Plex will still be able to transcode a few files if need be while my space is low. Make note of the section labeled ‘Scripts Folder’ because this is where SABnzbd looks for scripts. Copy/paste the script below and save it in this directory.

Next, you’ll head over to the section labeled ‘Notifications’ and scroll to the bottom. You’ll see a ‘Notification Script’ secion. Choose the script you just saved from the drop-down, and check the ‘Warning’ box to trigger this script with warnings, and then check ‘Enable notification script’ under the section header. SABnzbd passes a number of arguments to this script, the third of which is the notification comment which defines the warning. Since we only want this script to run after warnings for low disk space, it will look at this variable for the word “disk” and only run if its present.

#!/bin/bash

if [[ "$3" != 0 ]] && [[ "$3" == *"disk"* ]]; then

while [ $(df -H | grep /dev/md2 | awk '{sub( "G", "", $4); print $4; }') -lt 100 ] ;
do
 echo "Disk full - $(df -H | grep mapper | awk '{print $4}') free"
 sleep 30s
done
echo "disk space free"
curl "http://127.0.0.1:8080/api?apikey=YOURAPIKEYHERE&mode=resume"
curl "http://127.0.0.1:8080/api?apikey=YOURAPIKEYHERE&mode=warnings&name=clear"
else
echo "not triggered by disk warning"
exit
fi
exit
Advertisements

One thought on “SABnzbd Disk Monitor Script

  1. I was wondering if you could explain this code a bit?

    I was using it before, with a digital ocean account, so the disk where sabnzbd was running was /dev/vda1, and it was running properly. Then I decided to add a block volume to do all the downloading so the main disk doesn’t get clogged.

    I thought I had modified the script accordingly – I used fdisk -l to list my disks, and they show, both the disk /dev/vda (with its device /dev/vda1) and the new disk, /dev/sda (with no devices). I changed /dev/vda1 to /dev/sda in my script, and now the script won’t run.

    If I run it from the command line, I get

    script.sh: 3: script.sh [[: not found
    not triggered by disk warning

    So it’s assuming one of the $3 conditions is false (probably because it’s not finding $3) and when I try to test the script from sabnzbd I get

    Notification script returned exit code -1 and output “Cannot run script /home/plex/scripts/script.sh”

    Thanks!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s