Linux guru? :)

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
MickeMM
Posts: 48
Joined: 03 Apr 2019, 10:52

Linux guru? :)

Post by MickeMM »

Im trying to run this script, but it runs both script.
Anyone know how to fix?

Shell: Select all

#!/bin/bash
PATH=/home/me/filebot-portable:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:/usr/local/bin

# Input Parameters
ARG_PATH="$1"
ARG_NAME="$2"
ARG_LABEL="$3"

# Configuration
CONFIG_OUTPUT="/mnt/omkoda/"

if [ ut_label=FILM ]; then
 /home/me/filebot-portable/filebot.sh -script fn:amc --output "$CONFIG_OUTPUT" --action hardlink -non-strict --conflict auto --log-file /home/me/logg/amc.log --def deleteAfterExtract=n --def clean=y --def excludeList="/home/me/logg/excludes" ut_dir="$ARG_PATH" ut_kind="multi" ut_title="$ARG_NAME" ut_label="$ARG_LABEL" --def movieFormat=@/home/me/filebot-portable/MovieFormat.groovy &
fi

if [ ut_label=SERIE ]; then
 /home/me/filebot-portable/filebot.sh -script fn:amc --output "$CONFIG_OUTPUT" --action copy -non-strict --conflict auto --log-file /home/me/logg/amc-serie.log --def deleteAfterExtract=n --def clean=y --def excludeList="/home/me/logg/excludes-serie" ut_dir="$ARG_PATH" ut_kind="multi" ut_title="$ARG_NAME" ut_label="$ARG_LABEL" --def seriesFormat="/mnt/plex/Serie/{plex}" &
fi

exit 0
Thanks!
User avatar
rednoah
The Source
Posts: 23343
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Linux guru? :)

Post by rednoah »

Console Output: Select all

$ [ ut_label=FILM ]
$ echo $?
0
:!: [ ut_label=FILM ] is always 0 because you're effectively doing a "check if variable has a value" test (e.g. [ "$TERM" ]) except with a surely defined value and not a variable.


:idea: Unrelated to that, ut_label is not a variable in the first place. Even if you did $ut_label it still wouldn't work because nobody is defining that variable. The parameters passed in via positional arguments are what you have:

Shell: Select all

# Input Parameters
ARG_PATH="$1"
ARG_NAME="$2"
ARG_LABEL="$3"



:idea: Know that [ is just an alias for the test command. Cmdline and Argument Passing (i.e. the number and position of argument values) is important just like with any other command.


Compare and Contrast:

Console Output: Select all

$ [ 'X' ]; echo $?
0
$ [ '' ]; echo $?
1
$ [ 'A=B' ]; echo $?
0
$ [ 'A' '=' 'B' ]; echo $?
1
$ [ A = B ]; echo $?
1
$ test A = B; echo $?
1



:arrow: You probably meant to do something like this:

Shell: Select all

if [ "$ARG_LABEL" = "SERIE" ]; then
  # process series
fi



:idea: General Advice: You'll want to add to use -xu for your shell shebang to enable debug mode, i.e. print commands so you see what's going on and error out when using undefined variables:

Shell: Select all

#!/bin/bash -xu
:idea: Please read the FAQ and How to Request Help.
Post Reply