Forum Discussion

David_G__33241's avatar
David_G__33241
Icon for Nimbostratus rankNimbostratus
Nov 22, 2015

base64 decode in bash

I am using Mark’s HSSR to call a BASH script:

 

set sts [call /Common/HSSR::http_req \
    -uri "https://127.0.0.1/mgmt/tm/util/bash/" \
    -userid admin-fid \
    -passwd 123abc \
    -virt /Common/vs-HSSR-helper \
    -method "POST" \
    -body "{\"command\":\"run\",\"utilCmdArgs\":\"-c '/shared/work/script.sh -m $csr_mgremail -n $csr_mgrfullname'\"}" \
    -rbody rbody]

 

Some of my variable values contain spaces or special characters such as a single quote. Ideally I would like to call the script using

… -n “$scr_mgrfullname” …

…however I cannot seem to figure out how to do this without getting an error:

 

Server returned status=400, content={"code":400,"message":"Found invalid JSON body in the request.","errorStack":[]}

 

I also tried escaping the quote with \” and also changing some single quotes to double quotes, etc. My work around was to do a string map and replace the space in the variable value with “%20” using string map, and then in the script change it back to the way it was by replacing “%20” with a space. I could also do this for the single quite but I am wondering if I will come across other issues such as when using French characters?

One thought I had was to b64encode the string before passing it as a variable but I have not yet figured out how to properly reverse the process in the bash script. I did find a couple ways to decode manually (both work) but I don’t know if either of these are efficient and I don’t know how to store the output in a variable:

 

openssl base64 -d <<< $variable
echo –n $variable | base64 -d -i

 

Is there a way to either change -body parameter to handle variables that contain special characters and if not can someone tell me the best way to b64decode the BASH parameter so that it can be stored in a variable?

Thank you

No RepliesBe the first to reply