Saturday, 25 February 2012

Conky SABnzbd script

Just a quick script Ive knocked up for conky to show SABnzbd's current status:


 #!/bin/bash  
 prntvalue () {  
      echo $XML | xmlstarlet sel -t -v "$1"  
 }  
 prntnumber () {  
      printf "%.2f\n" $(prntvalue "$1")  
 }  
 XML=$(wget -q -O - "http://YOUR-SAB-HOST:PORT/sabnzbd/api?mode=qstatus&output=xml&apikey=YOUR-API-KEY")  
 state=$(prntvalue "/queue/state")  
 state=`echo $state | tr [A-Z] [a-z]`  
 let nojobs=$(echo $XML | xmlstarlet sel -t -v "count(/queue/jobs/job)")  
 if [[ $nojobs > 0 ]];then  
      timeleft=$(prntvalue "/queue/timeleft")  
      totmbleft=$(prntnumber "/queue/mbleft")  
      totmb=$(prntnumber "/queue/mb")  
      kbpersec=$(prntnumber "/queue/kbpersec")  
      if [ $state == "paused" ]; then  
           echo "SABnzbd+ $state. $nojobs items queued."  
      else       
           echo "SABnzbd+ $state @$kbpersec k/s Downloading $nojobs items ETA:$timeleft"  
      fi  
 else  
      echo -e "SABnzbd+ is $state"  
 fi  
 exit 0 
It outputs something like this:
 SABnzbd+ paused. 14 items queued.  
Also, thanks to http://codeformatter.blogspot.com/ :)

1 comment:

  1. Awesome Cheers for this mate. Nice little script even 3 years on :)

    ReplyDelete