Page 1 of 1

Cannot Get Shell Scripts To Run In Fedora Core 14

Posted: November 29th, 2011, 8:03 pm
by DivinityCycle
Greetings! I've got a headless box running Fedora Core 14 with Transmission, SabNZBD+, Apache, CouchPotato, Sick beard, and some other stuff. I've been successfully using CouchPotato and SickBeard in tandem with an XBMC setup for close to a year now, which has been working beautifully. I recently decided to try and build my own automated games post-processor script to handle extracting ISOs and moving stuff around. Nothing extremely sophisticated. However, I am unable to get any scripts to even run :( I am familiar with shell scripting in general, and have a few basic maintenance scripts run by cron on my box.

I believe the issue is the manner in which sabnzbd is calling my script. I have a category called "Games", and have the script Games.sh associated with that category. From my Sab logs I see that my script is firing off like this:

Code: Select all

/usr/local/src/sabnzbd/scripts/Games.sh(/mnt/disk2/Downloads/Complete/Games/Nurarihyon No Mago Hyakki Ryouran Taisen JPN XBOX360 SuperX360, Nurarihyon No Mago Hyakki Ryouran Taisen JPN XBOX360 SuperX360.nzb, Nurarihyon No Mago Hyakki Ryouran Taisen JPN XBOX360 SuperX360, , games, alt.binaries.games.xbox360, 0)
There is no additional output even though my script is designed to spit out useful output about what's happening via echo.

When I try this same command via a terminal I get the same error every time: "syntax error near unexpected token" followed by the first argument that contains a space. So like the above line gets the results:

Code: Select all

-bash: syntax error near unexpected token `/mnt/disk2/Downloads/Complete/Games/Nurarihyon'
In general this would seem to be bash's way of saying "I don't understand the structure of the arguments you've given me". I initially thought I could get around the issue of the spaces being present by simply enabling the SAB option to replace spaces with underscores in the folder names, but then the issue just occurs further out in the call, in the second or third variable :( Because of how obscure the issue is I haven't been able to make much headway on fixing this issue, so I turn to you guys.

Here's the full text of my shell script so far:

Code: Select all

#!/bin/bash
clear
echo "1 is $1"
###############
# Settings    #
###############
#
# 360 Settings
#
################
Extract360ISO="Yes"
Delete360ISO="Yes"
Move360ISO="No"
Extract360Destination="/mnt/disk3/Games/Xbox360/Games/"
ISODestination360="/mnt/disk3/Games/Xbox360/ISO/"
DLCDestination360="/mnt/disk3/Games/Xbox360/DLC/"

##################
#
#Wii Settings####
#
#################
WiiExtractISO="Yes"
WiiDeleteISO="Yes"
WiiExtractDestination="/mnt/disk3/Games/Wii/Games/"
WiiISODestination="/mnt/disk3/Games/Wii/ISO/"
#
#

if [ $7 = "0" ]; 
then
		if [ $1 = *XBOX360* ];
		echo "Xbox 360 game found."
		then
			#prepare the release's "pretty name"
			# First we grab the release name from SABnzbd
			prettyname=$3
			# Next we replace all dots with spaces
			prettyname=$(echo ${prettyname//./ })
			# Then we do the same with underscores
			prettyname=$(echo ${prettyname//_/ })
			# Chop off the "Xbox360" and release group
			#prettyname=$(echo ${prettyname:0:$index})
			prettyname=${prettyname% XBOX360*}
			echo "Finished release name is $prettyname."
			echo "Looking for ISOs."
			ISOCount="0"
			#move into the directory where the job is
			cd "$1"
			# find the number of ISOs in the folder
			ISOCount=$( ls -1 | grep .iso | wc -l )
			# if there's more than 1 ISO we will process it as a multi-disc release
			if [ $ISOCount -gt 1 ];
			then
				ISOCountx="1"
				echo "Multi-disc release found."
				for f in *.iso;
				do
					if [ $Extract360ISO = "Yes" ];
					then
						echo "Extracting $f to $Extract360Destination$prettyname-Disc $ISOCountx";
						extract-xiso -x "$f" -d "$Extract360Destination$prettyname-Disc $ISOCountx";
					fi
					if [ $Move360ISO = "Yes" ];
					then
						echo "Moving $f to $ISODestination360$prettyname-Disc $ISOCountx.iso";
						mv "$f" "$ISODestination360$prettyname-Disc $ISOCountx.iso";
					fi
					if [[ $Delete360ISO = "Yes"  && $Move360ISO = "No" ]];
					then
						echo "Deleting $f";
						rm -f "$f";
					fi
					ISOCountx=`expr $ISOCountx + 1`;
				done
			fi
			if [ $ISOCount = "1" ];
			then
			# if its just one ISO we can process it withou the ISOCount stuff
				echo "Single disc release found."
				if [ $Extract360ISO = "Yes" ];
				then
					echo "Extracting $f to $Extract360Destination$prettyname";
					extract-xiso -x "$f" -d "$Extract360Destination$prettyname";
				fi
				if [ $Move360ISO = "Yes" ];
				then
					echo "Moving $f to $ISODestination360$prettyname.iso";
					mv "$f" "$ISODestination360$prettyname.iso";
				fi
				if [[ $Delete360ISO = "Yes"  && $Move360ISO = "No" ]];
				then
					echo "Deleting $f";
					rm -f "$f"
				fi
			fi
			if [ $ISOCount = "0" ];
			then
			# if no ISOs are found maybe its DLC?
				echo "No ISOs found, DLC?"
			fi
		fi
		#End Xbox 360 branch
else
	echo "Job didn't complete successfully?"
fi
It's had +x applied to it and I know it's working in general because I have done a lot of test calls on my own prior to having SABnzbd run it. I use Notepad++ and have this document set up with Unix style EOLs. The Wii-related and DLC-related settings aren't implemented yet, as I wanted to get the basics up and running before I get fancy with it. At the moment its pretty much just supposed to find Xbox 360 ISO files, figure out a relatively nice file/foldername to use, and extract them to where I want, then delete the ISOs.

Any suggestions?

Re: Cannot Get Shell Scripts To Run In Fedora Core 14

Posted: November 29th, 2011, 11:31 pm
by sander
Spaces in shell arguments / variables: I find that so difficult that I never do it. Maybe http://mywiki.wooledge.org/Quotes helps?

BTW:

if [ $1 = *XBOX360* ];

I don't think that does want you want. But, once again, I don't understand anything of shell arguments.

Re: Cannot Get Shell Scripts To Run In Fedora Core 14

Posted: November 30th, 2011, 12:25 am
by DivinityCycle
How does that fix SABnzbd's way of calling the script?

Re: Cannot Get Shell Scripts To Run In Fedora Core 14

Posted: November 30th, 2011, 1:12 am
by DivinityCycle
I just created a second script in my sabnzbd+'s scripts folder, named test.sh.
Its contents:

Code: Select all

#!/bin/bash
echo "HELLO WORLD!"
As you can see, this is just to test if the script is being run or not, since ALL it does is output "HELLO WORLD!".

I downloaded a very tiny 2MB release in the "Games" category, to test this out. Here's my sabnzbd+ debug log from around the end of the processing for that download:

Code: Select all

2011-11-29 21:48:46,607::INFO::[postproc:316] unpack_magic finished on Who_Wants_To_Be_A_Movie_Millionaire_DLC_XBOX360_MoNGoLS
2011-11-29 21:48:46,608::DEBUG::[misc:736] Moving. Old path:/mnt/disk2/Downloads/Incomplete/Who Wants To Be A Movie Millionaire DLC XBOX360 MoNGoLS/mgl-wwmm.sfv new path:/mnt/disk2/Downloads/Complete/Games/Who_Wants_To_Be_A_Movie_Millionaire_DLC_XBOX360_MoNGoLS.1/mgl-wwmm.sfv unique?:False
2011-11-29 21:48:46,609::DEBUG::[misc:736] Moving. Old path:/mnt/disk2/Downloads/Incomplete/Who Wants To Be A Movie Millionaire DLC XBOX360 MoNGoLS/mongols.nfo new path:/mnt/disk2/Downloads/Complete/Games/Who_Wants_To_Be_A_Movie_Millionaire_DLC_XBOX360_MoNGoLS.1/mongols.nfo unique?:False
2011-11-29 21:48:46,611::INFO::[postproc:627] Removing unwanted file /mnt/disk2/Downloads/Complete/Games/Who_Wants_To_Be_A_Movie_Millionaire_DLC_XBOX360_MoNGoLS.1/mgl-wwmm.sfv
[color=#800000]2011-11-29 21:48:46,614::INFO::[newsunpack:133] Running external script /usr/local/src/sabnzbd/scripts/test.sh(/mnt/disk2/Downloads/Complete/Games/Who_Wants_To_Be_A_Movie_Millionaire_DLC_XBOX360_MoNGoLS.1, Who Wants To Be A Movie Millionaire DLC XBOX360 MoNGoLS.nzb, Who_Wants_To_Be_A_Movie_Millionaire_DLC_XBOX360_MoNGoLS, , games, alt.binaries.games.xbox360, 0)[/color]
2011-11-29 21:48:46,651::INFO::[urlgrabber:110] Removing nzbmatrix bookmark 1105647
2011-11-29 21:48:46,936::INFO::[postproc:472] Cleaning up Who_Wants_To_Be_A_Movie_Millionaire_DLC_XBOX360_MoNGoLS (keep_basic=False)
2011-11-29 21:48:46,941::INFO::[postproc:83] Saving postproc queue
It clearly tries to fire off tesh.sh with the same non-working syntax.

If I try to reproduce it in a terminal, here's my results:

Code: Select all

[root@home ~]# /usr/local/src/sabnzbd/scripts/test.sh(/mnt/disk2/Downloads/Complete/Games/Who_Wants_To_Be_A_Movie_Millionaire_DLC_XBOX360_MoNGoLS, Who Wants To Be A Movie Millionaire DLC XBOX360 MoNGoLS.nzb, Who_Wants_To_Be_A_Movie_Millionaire_DLC_XBOX360_MoNGoLS, , games, alt.binaries.games.xbox360, 0)
-bash: syntax error near unexpected token `/mnt/disk2/Downloads/Complete/Games/Who_Wants_To_Be_A_Movie_Millionaire_DLC_XBOX360_MoNGoLS,'
[root@home ~]#
Basically, nothing will run if you execute it in with the command /path/to/some/script.xx(args, here, and here) as far as I can tell. I even tried a Python script that similarly just prints Hello World, same problem. I'm not certain how to make any scripts actually be run by sabnzbd :(

Re: Cannot Get Shell Scripts To Run In Fedora Core 14

Posted: November 30th, 2011, 2:17 am
by sander
I think you're mixing things up; the log file does not show how the arguments are passed; it's just python syntax.

So, to see that your script is run by SABnzbd, change it something like:

#!/bin/sh
date >> /tmp/hello.$$
echo $1 >> /tmp/hello.$$

(assuming the temp-dir is called /tmp)

Then see what appears in /tmp/ ...

Re: Cannot Get Shell Scripts To Run In Fedora Core 14

Posted: November 30th, 2011, 9:04 am
by DivinityCycle
Yeah I was basing my expectations on the documentation here: http://wiki.sabnzbd.org/user-scripts
Specifically, it says "The console output of the script is captured by SABnzbd and saved in a log file."
Naturally, you can understand why I expected the output from my script to be showing up in mySABnzbd log file...

Thanks a lot for the help!

I re-wrote my tester script like-so:
#!/bin/bash

Code: Select all

echo "1 is $1" >> /var/www/html/saboutput.txt
echo "2 is $2" >> /var/www/html/saboutput.txt
echo "3 is $3" >> /var/www/html/saboutput.txt
echo "4 is $4" >> /var/www/html/saboutput.txt
echo "5 is $5" >> /var/www/html/saboutput.txt
echo "6 is $6" >> /var/www/html/saboutput.txt
echo "7 is $7" >> /var/www/html/saboutput.txt
The output is this:

Code: Select all

1 is /mnt/disk2/Downloads/Complete/Games/Who_Wants_To_Be_A_Movie_Millionaire_DLC_XBOX360_MoNGoLS
2 is Who Wants To Be A Movie Millionaire DLC XBOX360 MoNGoLS.nzb
3 is Who_Wants_To_Be_A_Movie_Millionaire_DLC_XBOX360_MoNGoLS
4 is 
5 is games
6 is alt.binaries.games.xbox360
7 is 0
This is exactly what I was needing! I humbly suggest that maybe the documentation could be updated to reflect this?

Re: Cannot Get Shell Scripts To Run In Fedora Core 14

Posted: November 30th, 2011, 10:33 am
by jcfp
The script output is saved in "a log file" - just not the program log since that has only a very limited lifespan. Instead, the script output is part of the job history, and available in the web interface (usually by clicking on a particular job in the history)

Re: Cannot Get Shell Scripts To Run In Fedora Core 14

Posted: November 30th, 2011, 10:51 am
by DivinityCycle
Yup, I found it after posting. I wish that were in the docs, it would have made debugging a lot easier :P

Re: Cannot Get Shell Scripts To Run In Fedora Core 14

Posted: November 30th, 2011, 11:49 am
by jcfp