1 2 Previous Next 21 Replies Latest reply on Oct 15, 2019 5:02 AM by Greinger Longbotton

    Unexpected token '}' in expression or statement

    Greinger Longbotton
      Share This:

      Hello,

       

      we are running a PS1 on TruesSight Server Automation (TSA) Version: 8.9.04.227.

      The PS1 works fine when run directly  on a Windows machine, but it shows syntax errors when run from TSA.

       

      The error is always the same:

       

      Error 18-sep-2019 12:08:21 At C:\tmp\stage\4e8fe78a-d050-40c1-ba9e-29674cdf9d60.script_DBKey-SJobKeyImpl-2

      Error 18-sep-2019 12:08:21 857297-SCRIPT.ps1:1101 char:1

      Error 18-sep-2019 12:08:21 + }

      Error 18-sep-2019 12:08:21 + ~

      Error 18-sep-2019 12:08:21 Unexpected token '}' in expression or statement.

      Error 18-sep-2019 12:08:21 + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordEx

      Error 18-sep-2019 12:08:21 ception

      Error 18-sep-2019 12:08:21 + FullyQualifiedErrorId : UnexpectedToken

       

      The scipt has no syntax errors at all, as I said, it works well when run from Powershell ISE on the target.

      Maybe the script is too long (1122 lines), can it be the source of the problem?

        • 1. Re: Unexpected token '}' in expression or statement
          Greinger Longbotton

          The brace "}" is closing an IF 451 lines long. Is it too long?

           

          650     > if (!(Get-EX16RemoteMailbox $NAME_MAIL_BOX)) {

          ...

          1101     }

          • 2. Re: Unexpected token '}' in expression or statement
            Greinger Longbotton

            Also, we are using the following special characters on some Write-Host command. Maybe the problem is there?

             

            1. ñ
            2. Ñ    <-- We think the problem is cused by this character
            3. á
            4. é
            5. í
            6. ó
            7. ú
            • 3. Re: Unexpected token '}' in expression or statement
              Greg Michael

              You might try the "1/2" method of debugging... This approach assumes that the script is being executed but is failing at the end.  If the script is not even being executed, then you'll have to start commenting out each line rather than exiting half way through.

               

              Add a break/exit 1/2 way through your code - if the error disappears, then it's in the 2nd half. If the error remains, it's in the first half.
              Continue dividing each "halved" section in half until you narrow it down to a small subset of lines of code.

              1 of 1 people found this helpful
              • 4. Re: Unexpected token '}' in expression or statement
                Bill Robinson
                The PS1 works fine when run directly  on a Windows machine, but it shows syntax errors when run from TSA.

                how are you running it through tssa ?

                • 5. Re: Unexpected token '}' in expression or statement
                  Greinger Longbotton

                  We think we have folloewd all the steps in the documentation:

                   

                  • 6. Re: Unexpected token '}' in expression or statement
                    Greinger Longbotton

                    Hello G. Michael,

                     

                    We have kind of done that, but the script is more 1200 lines long.

                    We have written this post to find out if there is some known issue about native powershell on TSSA.

                    Remember that the powershell works well when run out of TSSA.

                    • 7. Re: Unexpected token '}' in expression or statement
                      Greinger Longbotton

                      IMPORTANT: The checksums are different

                       

                      The PS1 script is located in the file server:

                       

                      //FILESERVER.company.com/storage/scripts/3791100.1_Rooms_Create_Objects.ps1

                       

                       

                      In the target (TARGETSERVER001) rscd.log you can see where the PS1 script will be copied and the name:

                      ...

                      09/19/19 09:42:38.207 INFO     rscd -  172.26.59.74 5472 BladeLogicRSCD@TARGETSERVER001->admintemp2@TARGETSERVER001:PrivilegeMapped (BLAdmins:USER01@COMPANY.COM): cp: cp -D //TARGETSERVER001/c/ -tf //@/opt/bmc/bladelogic/NSH/tmp/appserver01_JOB/scripts/job__9f5cd2a7-5db9-4375-82d7-1d795230573f/75abb71e-8770-419b-9f06-ab7e900b6b20.script_DBKey-SJobKeyImpl-2858415-2_Rooms_Create_Objects.ps1 /temp/stage/75abb71e-8770-419b-9f06-ab7e900b6b20.script_DBKey-SJobKeyImpl-2858415-2_Rooms_Create_Objects.ps1

                       

                      09/19/19 09:42:38.207 INFO1    rscd -  172.26.59.74 5472 BladeLogicRSCD@TARGETSERVER001->admin@TARGETSERVER001:PrivilegeMapped (BLAdmins:USER01@COMPANY.COM): cp: > 01011 Copy file //@/opt/bmc/bladelogic/NSH/tmp/appserver01_JOB/scripts/job__9f5cd2a7-5db9-4375-82d7-1d795230573f/75abb71e-8770-419b-9f06-ab7e900b6b20.script_DBKey-SJobKeyImpl-2858415-2_Rooms_Create_Objects.ps1 to //TARGETSERVER001/temp/stage/75abb71e-8770-419b-9f06-ab7e900b6b20.script_DBKey-SJobKeyImpl-2858415-2_Rooms_Create_Objects.ps1

                      ...

                       

                      I put a 5 minutes sleep in the PS1 script code in order to chek the target PS1 checksum and comapre it with the file server source PS1 checksum. And the checksums are different!

                      But if I copy the PS1 via commandline, the checksum is the same.

                      In my opinion this may cause problems.

                       

                      TARGETSERVER001% pwd

                      //TARGETSERVER001/c/Temp/stage

                      TARGETSERVER001% md5sum 75abb71e-8770-419b-9f06-ab7e900b6b20.script_DBKey-SJobKeyImpl-2858415-2_Rooms_Create_Objects.ps1

                       

                      d627d5ff983d6c7a09e6fb7a12f66484 75abb71e-8770-419b-9f06-ab7e900b6b20.script_DBKey-SJobKeyImpl-2858415-2_Rooms_Create_Objects.ps1

                       

                      TARGETSERVER001% md5sum //FILESERVER.company.com/storage/scripts/3791313.1_Rooms_Create_Objects.ps1

                       

                      67f5c2f02f484bafd26026bf3d017349 //FILESERVER.company.com/storage/scripts/3791313.1_Rooms_Create_Objects.ps1

                       

                      TARGETSERVER001% cp //FILESERVER.company.com/storage/scripts/3791313.1_Rooms_Create_Objects.ps1 .

                       

                      TARGETSERVER001% ls -ltr

                      total 1

                      -rw-rw-rw-    1 Administrators 0             243 Sep 19 09:44 3791313.1_Rooms_Create_Objects.ps1

                       

                      TARGETSERVER001% md5sum 3791313.1_Rooms_Create_Objects.ps1

                      67f5c2f02f484bafd26026bf3d017349 3791313.1_Rooms_Create_Objects.ps1

                       

                       

                       

                      Also, the 2 files have different volumes but the command "diff" does not find any difference and the encoding apparently is the same (ASCII)

                       

                       

                      TARGETSERVER001% file 75abb71e-8770-419b-9f06-ab7e900b6b20.script_DBKey-SJobKeyImpl-2858415-2_Rooms_Create_Objects.ps1

                      75abb71e-8770-419b-9f06-ab7e900b6b20.script_DBKey-SJobKeyImpl-2858415-2_Rooms_Create_Objects.ps1: ASCII text

                       

                      TARGETSERVER001% file //FILESERVER.company.com/storage/scripts/3791313.1_Rooms_Create_Objects.ps1

                      //FILESERVER.company.com/storage/scripts/3791313.1_Rooms_Create_Objects.ps1: ASCII text

                       

                      TARGETSERVER001% ls -l //FILESERVER.company.com/storage/scripts/3791313.1_Rooms_Create_Objects.ps1

                      -rwx------    1 root     root          244 Sep 19 11:22 //FILESERVER.company.com/storage/scripts/3791313.1_Rooms_Create_Objects.ps1

                       

                      TARGETSERVER001% ls -l 75abb71e-8770-419b-9f06-ab7e900b6b20.script_DBKey-SJobKeyImpl-2858415-2_Rooms_Create_Objects.ps1

                      -rw-rw-rw-    1 Administrators 0             253 Sep 19 11:43 75abb71e-8770-419b-9f06-ab7e900b6b20.script_DBKey-SJobKeyImpl-2858415-2_Rooms_Create_Objects.ps1

                       

                      TARGETSERVER001% diff 75abb71e-8770-419b-9f06-ab7e900b6b20.script_DBKey-SJobKeyImpl-2858415-2_Rooms_Create_Objects.ps1       //FILESERVER.company.com/storage/scripts/3791313.1_Rooms_Create_Objects.ps1

                       

                      TARGETSERVER001%

                      2 of 2 people found this helpful
                      • 8. Re: Unexpected token '}' in expression or statement
                        German Coll

                        Maybe TSSA, in its internal process, does not use the NSH console to copy the script from the file server to the target server that modifies it.

                        Is there a way to find out how it is done?

                        • 9. Re: Unexpected token '}' in expression or statement
                          Bill Robinson

                          it should be using scriptutil to do the copy.  have you tried running this via scriptutil ? 

                           

                          also - when you copied the script from the file server to the target, do you try and execute that copy of the ps1 script to make sure that works ? 

                          • 10. Re: Unexpected token '}' in expression or statement
                            Greg Wojan

                            Out of curiosity, have you validated that the file is UTF8 without BOM and uses consistent Unix OR Windows line endings?

                             

                            FWIW, I have started using only Unix line endings in all my PowerShell scripts even on Windows, PowerShell doesn't really care, just in the off-chance one of my Unix environments doesn't like like the Windows CRLF...

                            • 11. Re: Unexpected token '}' in expression or statement
                              Greinger Longbotton

                              it should be using scriptutil to do the copy.  have you tried running this via scriptutil ?

                              Don't know how to do it. I don't find enough documentation about scriptutil to perfomr a copy

                               

                              also - when you copied the script from the file server to the target, do you try and execute that copy of the ps1 script to make sure that works ? 

                              Yes, but only with scripts that also work in BL. The error we are trying to solve here is shown before the execution of the powershell, that is during the validation of the code. So I cannot catch the script file when the validation fails because it doesn't perform the 5 minutes sleep whitin.

                              • 12. Re: Unexpected token '}' in expression or statement
                                Bill Robinson
                                Don't know how to do it. I don't find enough documentation about scriptutil to perfomr a copy

                                scriptutil -h <server> -s /path/to/script -x args 

                                you can look at the man page.

                                 

                                Yes, but only with scripts that also work in BL. The error we are trying to solve here is shown before the execution of the powershell, that is during the validation of the code.

                                you said you manually copied the non-working script from the file server to the target and looked at the md5sum.  did you then try and run it via powershell directly from the server (not via bsa) ?

                                 

                                So I cannot catch the script file when the validation fails because it doesn't perform the 5 minutes sleep whitin.

                                then how did you do this ?

                                I put a 5 minutes sleep in the PS1 script code in order to chek the target PS1 checksum and comapre it with the file server source PS1 checksum. And the checksums are different!

                                ?

                                 

                                 

                                trying to see where the problem is:

                                if you use 'cp' and copy the file server copy to the target and then run it directly via powershell (not inside bsa) does that work ?

                                if you use cp and copy the file server copy to the target and nexec it via powershell, does that work ?

                                if you run the script like the above where you got the different md5sum, is it possible to preserve a copy of that script on the target and directly run that ?

                                if you run the script via scriptutil what happens ?

                                • 13. Re: Unexpected token '}' in expression or statement
                                  German Coll

                                  I think I have an answer. The character "Ñ" might be a problem:

                                   

                                  This is my powershell code:

                                   

                                  -------------------------------------------------------------------------------------------------------

                                  param

                                  (

                                  [Parameter(Mandatory=$True, Position=1, HelpMessage="User")][string]$A,

                                  [Parameter(Mandatory=$True, Position=2, HelpMessage="Path")][string]$B

                                  )

                                   

                                  Write-Host "[1][1] $A"

                                  Write-Host "[2] $B"

                                   

                                  $C = "ESPAÑA"

                                  Write-Host "[3] $C"

                                   

                                  start-sleep 60

                                  -------------------------------------------------------------------------------------------------------

                                   

                                   

                                  And these are the parameters in TSSA:

                                   

                                   

                                  The script result should be:

                                   

                                  [1] españa

                                  [2] ESPAÑA

                                  [3] ESPAÑA

                                   

                                  But the result is:

                                  [1] españa

                                  [2] ESPAÑA

                                  [3] ESPAA`A

                                   

                                  And the scipt file copied in the target has the following content:

                                   

                                  -------------------------------------------------------------------------------------------------------

                                    param

                                          (

                                          [Parameter(Mandatory=$True, Position=1, HelpMessage="User")][string]$A,

                                          [Parameter(Mandatory=$True, Position=2, HelpMessage="Path")][string]$B

                                          )

                                   

                                  Write-Host "[1] $A"

                                  Write-Host "[2] $B"

                                   

                                  $C = "ESPAÃA"

                                  Write-Host "[3] $C"

                                  -------------------------------------------------------------------------------------------------------

                                   

                                  TSSA does not accept "Ñ" on the code but it accepts it from an external parameter.

                                   

                                  The character "Ñ" is not supported (which I think is a big issue for the latin world)

                                  3 of 3 people found this helpful
                                  1 2 Previous Next