[bash] -bash: syntax error near unexpected token `)'

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
wylandplex
Posts: 6
Joined: 29 Aug 2018, 14:22

[bash] -bash: syntax error near unexpected token `)'

Post by wylandplex »

Code: Select all

sudo -H -u mpadmin bash -c 'filebot -script fn:amc --output "/mnt/PDB1" --action test -non-strict "/mnt/PDB1/_torrents/complete" --conflict auto --log-file amc.log --def movieFormat="1_Movies/{n} ({y})/{n} ({y}){' CD'+pi}{'.'+lang}" seriesFormat="2_TV Shows/{n}/{episode.special ? 'Special' : 'Season '+s.pad(2)}/{n} - {episode.special ? 'S00E'+special.pad(2) : s00e00} - {t.replaceAll(/[`´‘’ʻ]/, /'/).replaceAll(/[!?.]+$/).replacePart(', Part $1')}{'.'+lang}" animeFormat="3_Anime+Cartoon/{primaryTitle}/{primaryTitle} - {sxe} - {t.replaceAll(/[!?.]+$/).replaceAll(/[`´‘’ʻ]/, /'/).replacePart(', Part $1')}" musicFormat="5_Music/{n}/{album+'/'}{pi.pad(2)+'. '}{artist} - {t}" clean=y music=y plex=[placeholder]'
Following Error Code:

Code: Select all

-bash: syntax error near unexpected token `)'

When I run the command directly it works just fine

In the end I want to run it as a "transmission script" but I want to run it under the user "mpadmin" anyway.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: ams script isn't working when executed as different user

Post by rednoah »

This tutorial explains why it doesn't work, i.e. your command-line is just wrong, unrelated to FileBot:
viewtopic.php?f=4&t=1899


The smart kids will create a bash script so they don't have to worry about escaping complex command-line arguments correctly:

Code: Select all

sudo -H -u mpadmin /path/to/my/script/that/calls/filebot/amc.sh
:idea: Please read the FAQ and How to Request Help.
wylandplex
Posts: 6
Joined: 29 Aug 2018, 14:22

Re: [bash] -bash: syntax error near unexpected token `)'

Post by wylandplex »

I switched over to qbittorrent meanwhile. Because I had exactly the same idear. When I bring it to work, I'll post a description for future users.
wylandplex
Posts: 6
Joined: 29 Aug 2018, 14:22

Re: [bash] -bash: syntax error near unexpected token `)'

Post by wylandplex »

Command I use in qbt:

Code: Select all

sudo -H -u mpadmin /home/mpadmin/scr/amc.sh
Script:

Code: Select all

filebot -script fn:amc --output "/mnt/PDB1" --action test -non-strict --conflict auto --log-file amc.log --def movieFormat="1_Movies/{n} ({y})/{n} ({y}){' CD'+pi}{'.'+lang}" seriesFormat="2_TV Shows/{n}/{episode.special ? 'Special' : 'Season '+s.pad(2)}/{n} - {episode.special ? 'S00E'+special.pad(2) : s00e00} - {t.replaceAll(/[`´‘’ʻ]/, /'/).replaceAll(/[!?.]+$/).replacePart(', Part $1')}{'.'+lang}" animeFormat="3_Anime+Cartoon/{primaryTitle}/{primaryTitle} - {sxe} - {t.replaceAll(/[!?.]+$/).replaceAll(/[`´‘’ʻ]/, /'/).replacePart(', Part $1')}" musicFormat="5_Music/{n}/{album+'/'}{pi.pad(2)+'. '}{artist} - {t}" clean=y unsorted=y excludeList=".excludes" "ut_dir=%F" "ut_kind=multi" "ut_title=%N" "ut_label=%L" plex=5qDBhGu8UmKBZTYjFxqT  
Output when I execute the "script" directly in cmd (Everything seems to work fine):
-->

Code: Select all

mpadmin@wyland-s1:/mnt/root_ext/outsourcing/linux/home/sexyuser$ filebot -script fn:amc --output "/mnt/PDB1" --action test -non-strict --conflict auto --log-file amc.log --def movieFormat="1_Movies/{n} ({y})/{n} ({y}){' CD'+pi}{'.'+lang}" seriesFormat="2_TV Shows/{n}/{episode.special ? 'Special' : 'Season '+s.pad(2)}/{n} - {episode.special ? 'S00E'+special.pad(2) : s00e00} - {t.replaceAll(/[`´‘’ʻ]/, /'/).replaceAll(/[!?.]+$/).replacePart(', Part $1')}{'.'+lang}" animeFormat="3_Anime+Cartoon/{primaryTitle}/{primaryTitle} - {sxe} - {t.replaceAll(/[!?.]+$/).replaceAll(/[`´‘’ʻ]/, /'/).replacePart(', Part $1')}" musicFormat="5_Music/{n}/{album+'/'}{pi.pad(2)+'. '}{artist} - {t}" clean=y unsorted=y excludeList=".excludes" "ut_dir=%F" "ut_kind=multi" "ut_title=%N" "ut_label=%L" plex=5qDBhGu8UmKBZTYjFxqT
bash: command substitution: line 1: unexpected EOF while looking for matching `''
bash: command substitution: line 2: syntax error: unexpected end of file
Locking /home/mpadmin/.filebot/logs/amc.log
Run script [fn:amc] at [Fri Oct 19 19:25:10 CEST 2018]
Parameter: movieFormat = 1_Movies/{n} ({y})/{n} ({y}){' CD'+pi}{'.'+lang}
Parameter: seriesFormat = 2_TV Shows/{n}/{episode.special ? 'Special' : 'Season '+s.pad(2)}/{n} - {episode.special ? 'S00E'+special.pad(2) : s00e00} - {t.replaceAll(/[´‘’ʻ]/, /'/).replacePart(', Part ')}
Parameter: musicFormat = 5_Music/{n}/{album+'/'}{pi.pad(2)+'. '}{artist} - {t}
Parameter: clean = y
Parameter: unsorted = y
Parameter: excludeList = .excludes
Parameter: ut_dir = %F
Parameter: ut_kind = multi
Parameter: ut_title = %N
Parameter: ut_label = %L
Parameter: plex = *****

----------------------------------- <README> -----------------------------------

Dear Linux user, mpadmin,

FileBot currently only officially supports Windows 10 and macOS because these platforms make it easy to sell FileBot via their respective app stores. Unfortunately, selling software on Ubuntu, Debian, Red Hat, SUSE, Synology NAS, QNAP NAS, etc is not as easy and not really worth the effort considering the small number of users willing to support the project. This Patreon is an experiment to see how many users are willing to financially contribute towards freely available donation-supported new releases on these platforms.

Please support FileBot for Linux with a pledge of $1 per release on Patreon:

=> https://www.patreon.com/filebot

If every other Linux user were to pledge a small amount of money to the FileBot project, then you could easily fund the project ten times over. Please financially support the software you use and rely on, be it FileBot or any other tool. It's just polite, and it helps the ecosystem.

Thank you,
The FileBot Team

---------------------------------- </README> -----------------------------------

Bad ut_dir value: %F
Bad ut_title value: %N
Bad ut_label value: %L
Illegal usage: no input
Failure (°_°)


The amc.sh works somehow if I switch user on shell & then execute amc.sh (I get errror but filebot gets executed anyway)
-->

Code: Select all

mpadmin@wyland-s1:/mnt/root_ext/outsourcing/linux/home/sexyuser$ /home/mpadmin/scr/amc.sh
/home/mpadmin/scr/amc.sh: command substitution: line 1: unexpected EOF while looking for matching `''
/home/mpadmin/scr/amc.sh: command substitution: line 2: syntax error: unexpected end of file
Locking /home/mpadmin/.filebot/logs/amc.log
Run script [fn:amc] at [Fri Oct 19 19:22:22 CEST 2018]
Parameter: movieFormat = 1_Movies/{n} ({y})/{n} ({y}){' CD'+pi}{'.'+lang}
Parameter: seriesFormat = 2_TV Shows/{n}/{episode.special ? 'Special' : 'Season '+s.pad(2)}/{n} - {episode.special ? 'S00E'+special.pad(2) : s00e00} - {t.replaceAll(/[´‘’ʻ]/, /'/).replacePart(', Part ')}
Parameter: musicFormat = 5_Music/{n}/{album+'/'}{pi.pad(2)+'. '}{artist} - {t}
Parameter: clean = y
Parameter: unsorted = y
Parameter: excludeList = .excludes
Parameter: ut_dir = %F
Parameter: ut_kind = multi
Parameter: ut_title = %N
Parameter: ut_label = %L
Parameter: plex = *****

----------------------------------- <README> -----------------------------------

Dear Linux user, mpadmin,

FileBot currently only officially supports Windows 10 and macOS because these platforms make it easy to sell FileBot via their respective app stores. Unfortunately, selling software on Ubuntu, Debian, Red Hat, SUSE, Synology NAS, QNAP NAS, etc is not as easy and not really worth the effort considering the small number of users willing to support the project. This Patreon is an experiment to see how many users are willing to financially contribute towards freely available donation-supported new releases on these platforms.

Please support FileBot for Linux with a pledge of $1 per release on Patreon:

=> https://www.patreon.com/filebot

If every other Linux user were to pledge a small amount of money to the FileBot project, then you could easily fund the project ten times over. Please financially support the software you use and rely on, be it FileBot or any other tool. It's just polite, and it helps the ecosystem.

Thank you,
The FileBot Team

---------------------------------- </README> -----------------------------------

Bad ut_dir value: %F
Bad ut_title value: %N
Bad ut_label value: %L
Illegal usage: no input
Failure (°_°)


When I execute it from a different user with "sudo -H -u mpadmin /home/mpadmin/scr/amc.sh" nothing works anymore:

Code: Select all

/home/mpadmin/scr/amc.sh: 1: /home/mpadmin/scr/amc.sh: Syntax error: Unterminated quoted string

I did read the link you postet. But I really don't see the solution to the problem...
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [bash] -bash: syntax error near unexpected token `)'

Post by rednoah »

You'll probably need to add a bash shebang:
https://stackoverflow.com/a/52860837/1514467


Presumably, you're using bash to execute the script when logged in, but the system might be using sh without login shell, which means some bash features may not work when interpreted with sh.


Moreover, according to your logs, even bash complains that your command isn't exactly valid:

Code: Select all

bash: command substitution: line 1: unexpected EOF while looking for matching `''
bash: command substitution: line 2: syntax error: unexpected end of file

:arrow: My link explains how to use "..." and '...' and how to escape argument values that contain " or ' which is a very common issue for beginners. You can avoid this altogether by passing in complex arguments via text files instead of command-line arguments :arrow: viewtopic.php?f=4&t=3244
:idea: Please read the FAQ and How to Request Help.
Post Reply