mm2270 / Casper-API

Casper Suite JSS API scripts and applications
66 stars 10 forks source link

Unexpected token for all `< <(` elements #3

Closed apizz closed 7 years ago

apizz commented 7 years ago

After trying to run several of the report bash scripts on our JSS box, I keep getting an error whenever there is a for-do statement that has a done < <( statement. See error example below:

/Users/admin/Scripts/Create-JSS-Policy-Scope-Report.sh: line 56: syntax error near unexpected token<' /Users/admin/Scripts/Create-JSS-Policy-Scope-Report.sh: line 56: done < <(printf '%s\n' "$ALL_POLICY_IDS")'

JSS is running on a machine running OS X 10.10.4. Please let me know if there's any additional info you need from me or know why this error would be occurring when trying to run these scripts. Thank you!

mm2270 commented 7 years ago

Hi @apizz This is a common question I get with many of my bash scripts. I suspect what's happening is you're trying to run the script in the following manner:

sh /path/to/Create-JSS-Policy-Scope-Report.sh

The issue here is that the script is specifically designed as a bash script (/bin/bash), and is using a bash construct sometimes called process substitution. If you run the command in Terminal with a sh in front, you're telling it to run it as Bourne shell script (/bin/sh) and it errors like that since it doesn't understand the while read - done loop (process substitution)

Instead of using sh /path/to/script.sh try making the script executable first - chmod +x /path/to/script.sh and then just do /path/to/script.sh instead, which will let it use the interpreter in the script, and it should work. If after doing that it still errors, let me know and I'll look into it.

apizz commented 7 years ago

Thanks for that @mm2270 . That allows me to run the script, however I'm getting a lot of parser errors, which is resulting in the script only taking one second to run and not including any data in the .csv file. Since this is a bash script, should I only use lower and upper case letters (no special charcaters) in the API username and password? Errors below:

Obtaining all JSS Package IDs... -:1: parser error : Document is empty

^ -:1: parser error : Start tag expected, '<' not found

^ Obtaining all JSS Policy IDs... -:1: parser error : Document is empty

^ -:1: parser error : Start tag expected, '<' not found

^ Obtaining all Casper Admin Configuration IDs... -:1: parser error : Document is empty

^ -:1: parser error : Start tag expected, '<' not found

^ Creating working directory structure... Creating working directory structure... Getting all Policy details for later package comparison (this step may take some time)... /Users/admin/Scripts/JSS-Package-Report.sh: line 119: /tmp/workingDir/Policies/: Is a directory -:1: parser error : Document is empty

^ -:1: parser error : Start tag expected, '<' not found

^ Policy ID done... Getting all Casper Admin Configuration details for later package comparison... /Users/admin/Scripts/JSS-Package-Report.sh: line 126: /tmp/workingDir/Configs/: Is a directory -:1: parser error : Document is empty

^ -:1: parser error : Start tag expected, '<' not found

^ Config ID done... All Policy and Configuration details successfully pulled down... Getting first package ID value... Getting header strings for csv... -:1: parser error : Document is empty

^ -:1: parser error : Start tag expected, '<' not found

^ Converting raw header strings into final header strings... Sending final header strings into temp file... Please wait while we cross reference all packages, policies and configurations... Getting package details for ID ... -:1: parser error : Document is empty

^ -:1: parser error : Start tag expected, '<' not found

^ Searching all policies and configurations for ID ...

Finalizing csv file...

The final csv file has been moved to your Desktop, named "jss.themastersschool.com_Packages_2016-10-26.csv" Script run complete Cleaning up resource files... Script completed at: Oct 26 2016, 10:39:38, total run time: 1 Seconds

mm2270 commented 7 years ago

Thanks @apizz. It looks to me like the API account you're using doesn't have the correct privileges to obtain the data. The script is receiving blank information and its trying to parse data that doesn't exist, and is throwing those errors as a result. I would double check your API account to be sure it has the correct read permissions on the JSS objects.

apizz commented 7 years ago

@mm2270 will do! Thanks so much.

apizz commented 7 years ago

@mm2270 think it was combination of special characters I used in the apiuser password and api read permissions. Just finished running the JSS-Package-Report.sh successfully and am now working to determine our crufty packages. Thanks for helping the api noob :)

apizz commented 7 years ago

Should have checked the previous closed issues facepalm

mm2270 commented 7 years ago

No worries. Thanks for confirming you got it working, and glad its able to help out!