[SOLVED] $1 for post-proc scripts on Linux has no value

Report & discuss bugs found in 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.
Post Reply
ericab
Newbie
Newbie
Posts: 12
Joined: May 26th, 2009, 5:03 pm

[SOLVED] $1 for post-proc scripts on Linux has no value

Post by ericab »

as the topic says;

$1 for post-proc scripts on Linux has no value.
i couldn't figure out why my post proc script (which cleans up some junk files for TV *only*, ie; nfo, srr, url, txt, etc etc... ---- note this is why im not using the built in junk cleaner) would not remove junk anymore.

to verify this; i added a simple "echo $1" in my script, and after a show had downloaded, i checked the script log.
there was no echo of its value.

anyone else see this as well ?

**edit
i should note that that behavior surface on either 0.7.10, or 0.7.11


**edit 2
it seems $5 also has no value
Last edited by ericab on February 12th, 2013, 7:52 pm, edited 1 time in total.
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: $1 for post-proc scripts on Linux has no value anymore

Post by shypike »

Did you test with the sample script in SABnzbd's distribution?
What does that give.

Listing the script here (Sample-PostProc.sh):

Code: Select all

#!/bin/sh
# Example of a post processing script for SABnzbd

echo
echo Started as $0
echo
echo "The first parameter (result-dir)  =" "$1"
echo "The second parameter (nzb-name)   =" "$2"
echo "The third parameter (nice name)   =" "$3"
echo "The fourth parameter (newzbin-id) =" "$4"
echo "The fifth parameter (category)    =" "$5"
echo "The sixth parameter (group)       =" "$6"
echo "The seventh parameter (status)    =" "$7"
echo
ericab
Newbie
Newbie
Posts: 12
Joined: May 26th, 2009, 5:03 pm

Re: $1 for post-proc scripts on Linux has no value anymore

Post by ericab »

i ran post-proc with that script and it works !
this is what i get:

Started as /home/eric/Dropbox/Code/Scripts/SABnzbd/sample

The first parameter (result-dir) = /home/eric/_Downloads/_TV/American Dad/s08
The second parameter (nzb-name) = American.Dad.S08E11.HDTV.x264-LOL.nzb
The third parameter (nice name) = American_Dad_S08E11_HDTV_x264-LOL
The fourth parameter (newzbin-id) =
The fifth parameter (category) = tv
The sixth parameter (group) = alt.binaries.teevee
The seventh parameter (status) = 0

now when i download the same file, with my script, (here is really simple junk remover script btw)

GARBAGE=".nfo .sfv .srt .srr .url .txt"

echo
for junk in $GARBAGE
do
echo "Removing: $junk"
find "$1" -name *$junk -type f -exec rm -f {} \;

done


i get this:


Removing: .nfo
find: cannot search `': No such file or directory
Removing: .sfv
find: cannot search `': No such file or directory
Removing: .srt
find: cannot search `': No such file or directory
Removing: .srr
find: cannot search `': No such file or directory
Removing: .url
find: cannot search `': No such file or directory
Removing: .txt
find: cannot search `': No such file or directory


\o/
ericab
Newbie
Newbie
Posts: 12
Joined: May 26th, 2009, 5:03 pm

Re: $1 for post-proc scripts on Linux has no value anymore

Post by ericab »

i think ive figured it out;
not sure why this happens, my bash script i posted above, is contained within a function.
if i remove it as a function, all works as it should.
User avatar
jcfp
Release Testers
Release Testers
Posts: 1004
Joined: February 7th, 2008, 12:45 pm

Re: $1 for post-proc scripts on Linux has no value anymore

Post by jcfp »

That's expected, see bash reference manual.
When a function is executed, the arguments to the function become the positional parameters during its execution (see Positional Parameters). The special parameter ‘#’ that expands to the number of positional parameters is updated to reflect the change. Special parameter 0 is unchanged. The first element of the FUNCNAME variable is set to the name of the function while the function is executing.
So you can't reference the global script arguments as $1 (etc.) in a function. Either pass those params to the function, or create regular vars out of them and use those inside the function.
ericab
Newbie
Newbie
Posts: 12
Joined: May 26th, 2009, 5:03 pm

Re: $1 for post-proc scripts on Linux has no value anymore

Post by ericab »

thanks jcfp @ shypike
Post Reply