Perl post-processing scripts

Come up with a useful post-processing script? Share it here!
Ambrotos
Newbie
Newbie
Posts: 7
Joined: February 11th, 2009, 9:57 pm

Perl post-processing scripts

Post by Ambrotos »

Given that there's plenty of discussion regarding various script types (Python, shell scripts, batch files, etc.), I assume that Sabnzbd isn't particular about the type of script executed post-processing, so long as there's an interpreter available and it receives its exit code. If true, then I wonder if someone could help me figure out why I'm having trouble getting a trivial Perl script to run properly.

I set the script to run via the category config, and wait for the download to finish. In the history menu, the process goes through the download, par, and unrar stages, then hangs with a status of "Running script...", and never seems to complete. Looking in the sabnzbd logs, it's clear that the script was started:

[newsunpack] Running external script D:\Shared\Usenet\scripts\showInfo.pl(etc...)

It's not likely an issue with the script hanging or getting stuck in a loop. I say that partly because CPU usage remains at idle, and partly because the script itself is trivial. At this stage I was just experimenting with what arguments were passed by sabnzbd to see what I had to work with:

Code: Select all

open OUT, ">args.log" or die "Canot open file: $!\n";

foreach (@ARGV) {
	print OUT "$_\n";
}

close(OUT);

exit 1;
Perl is installed properly, and I can run the script manually from the command line with no problems. Besides, if it were a problem with execution, I would expect sabnzbd to just immediately return an error.

Some particulars:
OS: Windows 2003
Perl: 5.10
Sabnzbd: 0.4.6

Any suggestions?

-A
markus101
Release Testers
Release Testers
Posts: 406
Joined: August 13th, 2008, 2:51 am

Re: Perl post-processing scripts

Post by markus101 »

If I understand correctly you're opening the args.log file and writing the available arguments into it, then closing it. Are you getting any output at all? By chance is the args.log file getting created, but not written to (if it needs to create a file). I have a feeling it has to do with how its supposed to write to the file...but I'm not sure. My guess is SAB runs the scripts in the BG somehow, which causes issues with the print functionality.

I'm having an issue with a script that runs an app (abgx360) hanging when it tries to write out the percentage it has completed of a CRC check - very frustrating. It appears to be almost the same issue you are seeing, I'm running Slackware 12.1, but it doesn't use any CPU time either (sits at 0.0% usage)...

Can anyone confirm how SAB runs the scripts in the BG, because it clearly differs from running them directly from the command line - it would be great to be able to test scripts exactly how SAB does, perhaps by passing arguments to a python script and having that script call a post-processing script the same way it would with running it through SAB after a download.

-Markus
Co-developer of NzbDrone (.Net NNTP PVR) - http://www.nzbdrone.com
rAf
Moderator
Moderator
Posts: 546
Joined: April 28th, 2008, 2:35 pm
Location: France
Contact:

Re: Perl post-processing scripts

Post by rAf »

hi,

maybe your script is working. Have you look in sabnzbd installation directory if there is not a args.log ?

Could you try to add a print  and change your args.log path like this and test :

Code: Select all

print "script is working";
open OUT, ">D:\\Shared\\Usenet\\args.log" or die "Canot open file: $!\n";

foreach (@ARGV) {
	print OUT "$_\n";
}

close(OUT);
print " !";
exit 1;
Hope it helps.
Ambrotos
Newbie
Newbie
Posts: 7
Joined: February 11th, 2009, 9:57 pm

Re: Perl post-processing scripts

Post by Ambrotos »

Actually, the code I inserted into my initial description was not a cut/paste, it was short enough I just retyped it. The actual script used by sabnzbd does not use relative paths. It is supposed to open the file d:\temp\args.log. This file is never created.

Also, even if the script were completed successfully, that still doesn't explain why the history status hangs on "Running script..." and never completes. Once the exit code is received, I imagine that status should get updated.

-A
Ambrotos
Newbie
Newbie
Posts: 7
Joined: February 11th, 2009, 9:57 pm

Re: Perl post-processing scripts

Post by Ambrotos »

In order to verify whether the problem lies in an issue with sabnzbd's BG-running of scripts and the print statement (as proposed by markus101), I tried the following script with the exact same results:

Code: Select all

foreach (@ARGV) {
    i++;
}
exit 1;
Sabnzbd is still stuck "Running script..." as I type this.

rAf: Where should I expect to see the output of the two print statements you've suggested? As far as I know, Sabnzbd doesn't display or log STDOUT anywhere...

-A
User avatar
sander
Release Testers
Release Testers
Posts: 8832
Joined: January 22nd, 2008, 2:22 pm

Re: Perl post-processing scripts

Post by sander »

@Ambrotos: can you correctly any script, for example a pre-fab script for SABnzbd?
Please don't send me unrequested PM's; the forum is the best way to communicate.
If someone helps you, please reply to that help.
f you like our support, check our special newsserver deal or donate at: https://sabnzbd.org/donate
Ambrotos
Newbie
Newbie
Posts: 7
Joined: February 11th, 2009, 9:57 pm

Re: Perl post-processing scripts

Post by Ambrotos »

Sander: Interestingly enough, it seems that I can execute batch files OK. I just tried a simple little...

Code: Select all

echo testing > c:\temp\scriptoutput.log
...and everything worked OK. It seems that the problem is particular to Perl.

I verified that the Perl interpreter binary is in the path of the user account used by Sabnzbd. Is there a way that I can manually specify how Sabnzbd executes particular scripts? i.e. can I explicitly call something like "c:\perl\bin\perl.exe script.pl"?

-A
markus101
Release Testers
Release Testers
Posts: 406
Joined: August 13th, 2008, 2:51 am

Re: Perl post-processing scripts

Post by markus101 »

You could get SAB to call a batch file that calls perl the way you want/need it to.

The below code should work to call it that way (it's an extra step unfortunately though).

Code: Select all

"c:\perl\bin\perl.exe script.pl" $1 $2 $3 $4 $5 $6 $7
-Markus
Co-developer of NzbDrone (.Net NNTP PVR) - http://www.nzbdrone.com
rAf
Moderator
Moderator
Posts: 546
Joined: April 28th, 2008, 2:35 pm
Location: France
Contact:

Re: Perl post-processing scripts

Post by rAf »

Do you have this line on top of your script ?

Code: Select all

#!C:/perl/bin/perl.exe
Ambrotos
Newbie
Newbie
Posts: 7
Joined: February 11th, 2009, 9:57 pm

Re: Perl post-processing scripts

Post by Ambrotos »

rAf: Yes, my script has the shebang as the first line.

markus101: I hadn't thought of that. Not a really elegant solution, but I'll give it a try.

-A
rAf
Moderator
Moderator
Posts: 546
Joined: April 28th, 2008, 2:35 pm
Location: France
Contact:

Re: Perl post-processing scripts

Post by rAf »

Ambrotos wrote: rAf: Where should I expect to see the output of the two print statements you've suggested? As far as I know, Sabnzbd doesn't display or log STDOUT anywhere...
If the script works, you have a

Code: Select all

Stage UserScript
[USER-SCRIPT]: => Show script output
With a link on "Show script output" to see the script output... so the print can give you hints.
Ambrotos
Newbie
Newbie
Posts: 7
Joined: February 11th, 2009, 9:57 pm

Re: Perl post-processing scripts

Post by Ambrotos »

lol. Unfortunately that doesn't help when your stage gets stuck on

Code: Select all


Stage UserScript
    [USER-SCRIPT]: => Running user script D:\Shared\Usenet\scripts\showInfo.pl 

That would explain why I hadn't noticed the show output link :)

-A
rAf
Moderator
Moderator
Posts: 546
Joined: April 28th, 2008, 2:35 pm
Location: France
Contact:

Re: Perl post-processing scripts

Post by rAf »

I think I've found why it's not working.
I try to reproduce your case and I have the same issue.
It's not working because perl scripts need a shell for execute and sabnzbd don't....
I'll discuss this issue with team.
rAf
Moderator
Moderator
Posts: 546
Joined: April 28th, 2008, 2:35 pm
Location: France
Contact:

Re: Perl post-processing scripts

Post by rAf »

I've tested the markus101 solution and it works
Here the command.bat :

Code: Select all

@echo off
"c:\perl\bin\perl.exe" "c:\temp\script.pl" "%1" "%2" "%3" "%4" "%5" "%6" "%7"
Hope it will work for you
Ambrotos
Newbie
Newbie
Posts: 7
Joined: February 11th, 2009, 9:57 pm

Re: Perl post-processing scripts

Post by Ambrotos »

I gave it a try myself, and everything seems to work ok so I should be able to continue with my scripting. Thanks for the help guys!

Any chance the ability to run perl scripts natively might make it into Sabnzbd 0.5.0? :)

-A
Post Reply