Page 1 of 2
Perl post-processing scripts
Posted: February 12th, 2009, 10:44 am
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
Re: Perl post-processing scripts
Posted: February 12th, 2009, 11:33 am
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
Re: Perl post-processing scripts
Posted: February 12th, 2009, 12:54 pm
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.
Re: Perl post-processing scripts
Posted: February 12th, 2009, 2:47 pm
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
Re: Perl post-processing scripts
Posted: February 12th, 2009, 7:02 pm
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:
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
Re: Perl post-processing scripts
Posted: February 13th, 2009, 1:23 am
by sander
@Ambrotos: can you correctly any script, for example a pre-fab script for SABnzbd?
Re: Perl post-processing scripts
Posted: February 13th, 2009, 2:15 am
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
Re: Perl post-processing scripts
Posted: February 13th, 2009, 2:29 am
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
Re: Perl post-processing scripts
Posted: February 13th, 2009, 4:51 am
by rAf
Do you have this line on top of your script ?
Re: Perl post-processing scripts
Posted: February 13th, 2009, 10:14 am
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
Re: Perl post-processing scripts
Posted: February 13th, 2009, 10:55 am
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.
Re: Perl post-processing scripts
Posted: February 13th, 2009, 11:24 am
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
Re: Perl post-processing scripts
Posted: February 13th, 2009, 11:46 am
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.
Re: Perl post-processing scripts
Posted: February 13th, 2009, 12:25 pm
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
Re: Perl post-processing scripts
Posted: February 14th, 2009, 2:23 pm
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