Cannot Get Shell Scripts To Run In Fedora Core 14
Posted: November 29th, 2011, 8:03 pm
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:
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:
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:
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?

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)
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'

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
Any suggestions?