Trying to use an example bash script provided by NewRelic to use their API. I get the following error:-

I get an error

27: Syntax error: word unexpected (expecting "in")

Can anyone see any issues here?

Here is the code and the page from Newrelic that I got it from.

    #!/bin/bash

# Admin API key from your account settings
adminAPIKey=''
# Other attributes found at https://docs.newrelic.com/docs/apis/synthetics-rest-api/monitor-examples/attributes-synthetics-rest-api#api-attributes
monitorName='Test API Script'
monitorType='SCRIPT_BROWSER'
frequency=1440
locations='"AWS_US_WEST_1", "AWS_US_EAST_1"'
slaThreshold=7.0
# Location of the file with your script
scriptfile=sample_synth_script.js

# Test that the script file exists (does not validate content)
if [ -e "$scriptfile" ]
then
  script=$(cat "$scriptfile")

  payload="{  \"name\" : \"$monitorName\", \"frequency\" : $frequency,    \"locations\" : [ $locations ],   \"status\" : \"ENABLED\",  \"type\" : \"$monitorType\", \"slaThreshold\" : $slaThreshold, \"uri\":\"\"}"
  echo "Creating monitor"

  # Make cURL call to API and parse response headers to get monitor UUID
  shopt -s extglob # Required to trim whitespace; see below
  while IFS=':' read key value; do
    # trim whitespace in "value"
    value=${value##+([[:space:]])}; value=${value%%+([[:space:]])}
    case "$key" in
        Location) LOCATION="$value"
                ;;
        HTTP*) read PROTO STATUS MSG <<< "$key{$value:+:$value}"
                ;;
    esac
  done < <(curl -sS -i  -X POST -H "X-Api-Key:$adminAPIKey" -H 'Content-Type: application/json' https://synthetics.newrelic.com/synthetics/api/v3/monitors -d "$payload")

  # Validate monitor creation & add script unless it failed
  if [ $STATUS = 201 ]; then
    echo "Monitor created, $LOCATION "
    echo "Uploading script"
      # base64 encode script
      encoded=`echo "$script" | base64`
      scriptPayload='{"scriptText":"'$encoded'"}'
        curl -s -X PUT -H "X-Api-Key:$adminAPIKey" -H 'Content-Type: application/json' "$LOCATION/script" -d $scriptPayload
        echo "Script uploaded"
  else
    echo "Monitor creation failed"
  fi

else
  echo "script file not found, not creating monitor"
fi

}}}

It's the scripted browser example at the bottom of the page.

[Newrelic](https://one.newrelic.com/launcher/api-keys-ui.api-keys-launcher?pane=eyJuZXJkbGV0SWQiOiJhcGkta2V5cy11aS5hcGkta2V5cy1uZXJkbGV0In0=&overlay=eyJjb250ZXh0TmVyZGxldElkIjpudWxsLCJjb250ZXh0RGlzcGxheU5hbWUiOm51bGwsIm5lcmRsZXRJZCI6Im5yMS1oZWxwLXhwLmhvbWUiLCJzZWFyY2hUZXJtIjoiYmFzaCBzY3JpcHQgZXhhbXBsZSJ9&platform[accountId]=2907802&platform[timeRange][duration]=1800000&platform[$isFallbackTimeRange]=true):



Read more here: https://stackoverflow.com/questions/65076505/trying-to-use-an-example-bash-script-provided-by-newrelic-to-use-their-api-i-ge

Content Attribution

This content was originally published by DireConseq at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: