Script to pause SABnzbd+ while PS3 running

Feel free to talk about anything and everything in this board.
Post Reply
mhardy85
Newbie
Newbie
Posts: 3
Joined: April 22nd, 2011, 7:10 am

Script to pause SABnzbd+ while PS3 running

Post by mhardy85 »

Hi everyone, hoping someone can point me in the right direction here. I have SABnzbd+ running on a headless Ubuntu server, and want a script which will pause any downloading while my PS3 is online. Currently I have the script below running every minute via cron, which does what I want, except for one problem. I can't manually pause downloading for any longer than one minute, because the script resumes it again. I've been trying to figure out a way to use variables to store a value indicating if the queue was paused from the script or another means. I can't figure out how to store a variable for later use. I'm assuming I need to write the value to a file, but I haven't had any luck getting that to work either.

Essentially, here's is what I'm trying to do:

If PS3 running, pause queue
If PS3 not running, but queue was paused outside of script, leave paused
If PS3 not running, and queue was paused via script, resume downloading

It seems like it should be fairly simple, but everything I have tried has failed so far. Any help, or even a push in the right direction would be greatly appreciated. Thank you.

Code: Select all

#!/bin/sh
#
# Script to pause SABnzbd+ when PS3 active
#

if ping -c 1 PS3
then
curl http://localhost:8085/api\?mode\=pause\&apikey\=<apikey>
else
curl http://localhost:8085/api\?mode\=resume\&apikey\=<apikey>
fi
mhardy85
Newbie
Newbie
Posts: 3
Joined: April 22nd, 2011, 7:10 am

Re: Script to pause SABnzbd+ while PS3 running

Post by mhardy85 »

Nevermind, I figured it out. It was bugging me I had to ask for help, which  made me look a bit harder, and put some more effort into figuring it out. It's all working great for me now.
mollydog
Newbie
Newbie
Posts: 35
Joined: August 26th, 2008, 7:37 am

Re: Script to pause SABnzbd+ while PS3 running

Post by mollydog »

Could you post your working script please. Thanks.
mhardy85
Newbie
Newbie
Posts: 3
Joined: April 22nd, 2011, 7:10 am

Re: Script to pause SABnzbd+ while PS3 running

Post by mhardy85 »

Here's what I'm using. I'm not a coder, so this may not be the best script, but it does the trick for me:

Code: Select all

#!/bin/sh
#
# Script to pause SABnzbd+ when PS3 active
#

# Retrieve variable from config file
script_paused=`cat PS3`

# Test if PS3 is online using ping (my PS3 uses static IP with a hostname of PS3, you may need to change this)
if ping -c 1 PS3
  then
  echo "Pausing..."
  # Send the pause command to SABnzbd+
  curl http://localhost:8085/api\?mode\=pause\&apikey\=<apikey>
  # Modify config file to show queue was paused by this script
  echo "yes" > PS3
else
  # If PS3 not running, and the queue was not paused by this script, do nothing
  if test $script_paused = no; then
    echo "Leaving alone..."
  else
  # If PS3 is not running, and queue was paused by this script, resume downloading
    echo "Resuming..."
    curl http://localhost:8085/api\?mode\=resume\&apikey\=<apikey>
    # Change config file to show the queue is no longer paused
    echo "no" > PS3
  fi
fi
You'll have to change the with your own from SABnzbd+
Post Reply