pre queue script JAVA problem

Get help with all aspects of SABnzbd
Forum rules
Help us help you:
  • Are you using the latest stable version of SABnzbd? Downloads page.
  • Tell us what system you run SABnzbd on.
  • Adhere to the forum rules.
  • Do you experience problems during downloading?
    Check your connection in Status and Interface settings window.
    Use Test Server in Config > Servers.
    We will probably ask you to do a test using only basic settings.
  • Do you experience problems during repair or unpacking?
    Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
warpAzrael
Newbie
Newbie
Posts: 13
Joined: May 16th, 2010, 1:50 pm

pre queue script JAVA problem

Post by warpAzrael »

Hi,

in my ever working pre que script, i added the following line

Code: Select all

found=$(java -jar "/boot/sabnzbduserscripts/tvshowcheck.jar" "$1" "get")
if i run the script manually, i get the desired output from the java program( found:YES or NO).
However if Sabnzbd runs the script, it simply outputs (found:) ant the script thinks it refueses the download.
2012-02-23 23:41:33,535::INFO::[newsunpack:1406] Running pre-queue script ['/usr/bin/ionice', '-c3', '/boot/sabnzbduserscripts/preProcess.sh', 'Seinfeld - 6x23 - The Face Painter', '3', 'tv', 'tvshowCompleteScript.sh', '1', '802432088', 'alt.binaries.tv.deutsch alt.binaries.ath alt.binaries.hdtv.german alt.binaries.teevee alt.binaries.cavebox', 'Seinfeld', '6', '23', 'The Face Painter']
2012-02-23 23:41:33,550::INFO::[newsunpack:1426] Pre-Q refuses Seinfeld - 6x23 - The Face Painter

there is no problem in the JAVA part, but how can i get my output back and why does the script think i refused the download?
User avatar
sander
Release Testers
Release Testers
Posts: 9070
Joined: January 22nd, 2008, 2:22 pm

Re: pre queue script JAVA problem

Post by sander »

AFAIK, a pre-processing script must produce a defined 7-line output (so not YES or NO). See http://wiki.sabnzbd.org/user-pre-queue-script for the format, or here:
Return parameters

The script writes the results to the console, each parameter on a separate line.
Each parameter (except 1) can be an empty line, meaning the original value.
1 : 0=Refuse, 1=Accept
2 : Name of the NZB (no path, no ".nzb")
3 : Post Processing (PP) flags: 0 = Download, 1 = +Repair, 2 = +Unpack, 3 = +Delete
4 : Category
5 : Script (basename)
6 : Priority (-100 -2, -1, 0 or 1, meaning Default, Paused, Low, Normal, High )
7 : Group to be used (in case your provider doesn't carry all groups and there are multiple groups in the NZB)

SABnzbd uses the first 7 lines of output, so they should only contain proper data (or be empty).
Anything after line 7 is ignored.
warpAzrael
Newbie
Newbie
Posts: 13
Joined: May 16th, 2010, 1:50 pm

Re: pre queue script JAVA problem

Post by warpAzrael »

it does output everything as defined. Here's the complete script

Code: Select all

#!/bin/bash
# All parameters (except 1) can be empty, meaning a default value.

# 1 : Name of the NZB (no path, no ".nzb")
# 2 : PP (0, 1, 2 or 3)
# 3 : Category
# 4 : Script (no path)
# 5 : Priority (-100, -1, 0 or 1 meaning Default, Low, Normal, High)
# 6 : Size of the download (in bytes)
# 7 : Group list (separated by spaces)
# 8 : Show name
# 9 : Season (1..99)
# 10 : Episode (1..99)
# 11: Episode name

# outputparams (what this script tells sabnzbd)
# The script writes the results to the console, each parameter on a separate line.
# Each parameter (except 1) can be an empty line, meaning the original value.
ret1=1	# 1 : 0=Refuse, 1=Accept
ret2=""	# 2 : Name of the NZB (no path, no ".nzb")
ret3=""	# 3 : PP (0, 1, 2 or 3)
ret4=""	# 4 : Category
ret5=""	# 5 : Script (basename)
ret6=""	# 6 : Priority (-100 -2, -1, 0 or 1, meaning Default, Paused, Low, Normal, High )
ret7=""	# 7 : Group to be used (in case your provider doesn't carry all groups and there are multiple groups in the NZB)

if [ "$3" = "tv" ]
  then

	found=$(java -jar tvshowcheck.jar "$1" "get")
	
	if [ "$found" = "YES" ] ; then
		#echo "already downloaded"
		ret6="-2" #pause
	fi

fi

echo $ret1 	# 1 : 0=Refuse, 1=Accept
echo $ret2	# 2 : Name of the NZB (no path, no ".nzb")
echo $ret3	# 3 : PP (0, 1, 2 or 3)
echo $ret4	# 4 : Category
echo $ret5	# 5 : Script (basename)
echo $ret6	# 6 : Priority (-100 -2, -1, 0 or 1, meaning Default, Paused, Low, Normal, High )
echo $ret7	# 7 : Group to be used (in case your provider doesn't carry all groups and there are multiple groups in the NZB)

however - it does not work
User avatar
sander
Release Testers
Release Testers
Posts: 9070
Joined: January 22nd, 2008, 2:22 pm

Re: pre queue script JAVA problem

Post by sander »

Can you run the script from the command line with different input parameters, and post the output here? See mine below. What if you put the full path in before the jar program to run?

Code: Select all

sander@netbook:~$ ./pp-script.sh blabla 3 23 3 3 3 3 3 
1






sander@netbook:~$ 
sander@netbook:~$ ./pp-script.sh blabla 3 tv 3 3 3 3 3 
Unable to access jarfile tvshowcheck.jar
1






sander@netbook:~$ 
warpAzrael
Newbie
Newbie
Posts: 13
Joined: May 16th, 2010, 1:50 pm

Re: pre queue script JAVA problem

Post by warpAzrael »

yes, if i run it manually from the commandline, everything works. If it is started by sabnzbd, it seems to stop outputting at exactly the line the java call is in.
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: pre queue script JAVA problem

Post by shypike »

Are the PATH and other environment variables identical for SABnzbd and your commandline?
warpAzrael
Newbie
Newbie
Posts: 13
Joined: May 16th, 2010, 1:50 pm

Re: pre queue script JAVA problem

Post by warpAzrael »

i'll try in a few hours.

As sidenote - this is running ona unRaid system - so everything is a little bit "special" ;)
warpAzrael
Newbie
Newbie
Posts: 13
Joined: May 16th, 2010, 1:50 pm

Re: pre queue script JAVA problem

Post by warpAzrael »

so i set PATH, but it didn't change anything. In the meanwhile i did a bash alternative for my JAVA program and it is working as desired, but it is annoying that JAVA, which i am much more familiar with, isn't working.
warpAzrael
Newbie
Newbie
Posts: 13
Joined: May 16th, 2010, 1:50 pm

Re: pre queue script JAVA problem

Post by warpAzrael »

so i figured it out now:

when the output of the JAVA program ist directly compared with the String "YES", it works!

so using this works:

Code: Select all

	if [ "$(java -jar /boot/sabnzbduserscripts/tvshowcheck.jar '$1' 'get')" = "YES" ]; then
		ret6="-2" #pause
	fi	
using that does NOT WORK:

Code: Select all

   found=$(java -jar /boot/sabnzbduserscripts/tvshowcheck.jar "$1" "get")
   
   if [ "$found" = "YES" ] ; then
      ret6="-2" #pause
   fi
i dont' know why, but i am happy now ;)
dreamscene
Newbie
Newbie
Posts: 20
Joined: April 11th, 2012, 10:09 pm

Re: pre queue script JAVA problem

Post by dreamscene »

I have run into similar issues while creating my pre-processing script. Apparently there seems to be a problem defining variables.

This works:

Code: Select all

if [ "$3" = "tv" ] && [ $6 -le 50000000 ]; then
        accept=0
else
        accept=1
fi

echo $accept
This does not work:

Code: Select all

category="$3"
size=$6
minsize=50000000

if [ "$category" = "tv" ] && [ $size -le $minsize ]; then
       accept=0
else
       accept=1
fi

echo $accept
A echo $category > /tmp/bla.log at the end of the script reveals that the $category variable is not set (bla.log is empty).
Running the same script from shell gives the desired output. Setting variables in a similar manner in a more sophisticated post-processing script works as well.

Am I missing something here or could there be a bug in sabnzbd regarding pre-processing?
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: pre queue script JAVA problem

Post by shypike »

Which shell are you using and on which OS?
I wouldn't be surprised if it's a problem with not being able to set variables to an empty string.
Works fine for me with SH and BASH on OSX.
dreamscene
Newbie
Newbie
Posts: 20
Joined: April 11th, 2012, 10:09 pm

Re: pre queue script JAVA problem

Post by dreamscene »

No dice with either BASH or SH on Linux :/
The script works and returns the expected output, though, when executed directly in the shell. Also setting variables in the same manner in a post-processing script is no problem at all, though unlike the category variable they are never empty.. so maybe you are on to something there. Still no clue why it works when executed directly.

When I am home I'll modify the script to set a default category if the string is empty and do some further testing.
Either way, thank you for your help :)
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: pre queue script JAVA problem

Post by shypike »

On Ubuntu 12.04 there's no problem either.
What OS are you using?
dreamscene
Newbie
Newbie
Posts: 20
Joined: April 11th, 2012, 10:09 pm

Re: pre queue script JAVA problem

Post by dreamscene »

Using Ubuntu Server 10.04.4 LTS and sabnzbd 0.7.4RC2.
Did some further testing with a script with some debug output and you were right - the problem is not setting variables, but setting an empty variable:

Code: Select all

#!/bin/bash

name="$1"
category="$3"
size=$6
minsize=50000000
time="$(date +%Y.%m.%d@%H:%M:%S)"

if [ $category = tv ] && [ $size -le $minsize ]; then
        accept=0
        echo $time REJECTED $name >> /tmp/pre-queue.log
else
        accept=1
fi

echo $accept

#debugging
echo name $name > /tmp/bla.log
echo category $category >> /tmp/bla.log
echo size $size >> /tmp/bla.log
echo minsize $minsize >> /tmp/bla.log
echo time $time >> /tmp/bla.log
echo accept $accept >> /tmp/bla.log

exit
Content of bla.log when a 10MB testfile is added to the TV category:

Code: Select all

name 10MB-3.bin
category tv
size 10835744
minsize 50000000
time 2012.10.03@07:49:41
accept 0
Content of bla.log when a 10MB testfile is added to the default (empty) category:

Code: Select all

name 10MB-3.bin
category
size 10835744
minsize 50000000
time 2012.10.03@07:50:18
accept 1
So when run by sabnzbd, the output of the script is as expected in both cases, even with the empty variable. What's unexpected is sabnzbd's behavior - because both times the NZB is not added to the queue.

Code: Select all

2012-10-03 07:50:17,980::INFO::[newsunpack:1445] Running pre-queue script ['/home/sabnzbd/scripts/pre-queue.sh', '10MB-3.bin', '', '', '', '-100', '10835744', 'alt.binaries.test', '', '', '', '']
2012-10-03 07:50:18,022::INFO::[newsunpack:1465] Pre-Q refuses 10MB-3.bin
When adding the testfile to any other category than default or testing for an empty category variable and setting a pseudo one, sabnzbd behaves as expected.
So you were definitely right. But why is sab behaving this way, even though the script produces the desired output (1 instead of 0)?
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: pre queue script JAVA problem

Post by shypike »

dreamscene wrote:But why is sab behaving this way, even though the script produces the desired output (1 instead of 0)?
Possibly some extraneous output?
SABnzbd assumes "accept" whenever something goes wrong (like a crashing or non-starting script).
You would have to debug SABnzbd for this.
Post Reply