Remove Whitelist(=) from the BASE64 encoded format in shell script for updating script

I am updating synthetic script using shell/bash command using below script

#!/bin/bash

Location of the file with your script

scriptfile=Test_Script.txt

if [ -e “$scriptfile” ]
then
script=$(cat “$scriptfile”)
echo “$script”

base64 encode script

encoded=echo "$script" | base64
echo “$encoded”
scriptPayload=’{“scriptText”:"’$encoded’"}’

echo “$scriptPayload”
curl -v -X PUT
-H ‘X-Api-Key: NA-438jfu0r2390320329329jfdcjdckca’
-H ‘Content-Type: application/json’
https://synthetics.newrelic.com/synthetics/api/v3/monitors/4hk34j-vdw2232-vv3333r-fvthy5bg/script
-d $scriptPayload
echo “Script uploaded”
fi

getting error c0FjdGl2ZSwgdHJ1ZSk7DQogICB9DQopOwo="}

how to remove = from the encoded string, i guess its adding whitespace.
Please suggest

#!/bin/bash

scriptfile=Test_script.js

if [ -e “$scriptfile” ]
then
script=$(cat “$scriptfile”)
echo “$script”

base64 encode script

encoded=echo "$script" | base64
echo “$encoded”
scriptPayload=’{“scriptText”:"’$encoded’"}’

echo “$scriptPayload”
curl -v -X PUT
-H ‘X-Api-Key: NRAA-435h4lj344rnmnnrm34nrb34r34’
-H ‘Content-Type: application/json’
https://synthetics.newrelic.com/synthetics/api/v3/monitors/r4rkjkr2-kbjkj32- n2r3nbkjrk2-54khbk/script’
-d $scriptPayload
echo “Script uploaded”
fi

Here i am getting whitespace = at the end of BASE64 ,which causing error while updating script in newrelic using shell/bash script

How to get rid of this = sign from base64
W5mby5pc0FjdGl2ZSwgdHJ1ZSk7DQogICB9DQopOwo="}

@sumitrajaram.bhagat Sorry to hear your having trouble with your script. Will reach out to one of our SMEs in this areas to see if they can provide some help. Thanks for your patience :slight_smile:

Joi

It has solved now by adding -w 0 at the end of BASE64

1 Like