Skip to main content Skip to complementary content

Building a Linux shell script to convert clear text to Base64 encoding string

Talend MetaServlet string needs to be encoded to Base64 when requesting Talend Administration Center MetaServlet REST API.

To post a JSON script, take metaservlet - “addServer” as an example, as shown below. This JSON sample adds a new Jobserver/Runtime server into Talend Administration Center server page.

{"actionName": "addServer","adminConsolePort": 8040,"authPass": "admin","authUser":"",
"commandPort": 8000,"description": "RemoteRT", "filePort": 8001,"host": "",
"instance": "trun", "label": "Remote RT server auto-scaling","mgmtRegPort": 1099,
"mgmtServerPort": 44444,"monitoringPort": 8888,"runtimePassword": "tadmin",
"runtimeUsername": "tadmin","shutdownBehavior": "Stop",
"timeoutUnknownState": "120","useSSL": false}


  1. Send this JSON script to the Talend Administration Center metaservlet API url. The REST WS call should be as follow:
    http://{TACHost}:8080/org.talend.administrator/metaServlet? {"actionName": "addServer",
    "adminConsolePort": 8040,"authPass":  "admin","authUser": "",
    "commandPort": 8000,"description": "RemoteRT","filePort": 8001,
    "host": "","instance": "trun","label": "Remote RT server auto-scaling",
    "mgmtRegPort": 1099,"mgmtServerPort": 44444,"monitoringPort": 8888,"runtimePassword":"tadmin",
    "runtimeUsername": "tadmin","shutdownBehavior": "Stop","timeoutUnknownState": "120","useSSL": false}
  2. However, the JSON string provided to the API url need to be encoded within Base64, so the final REST WS call will be as shown below:
  3. Encode the string by using the Linux shell script example shown below. Save the script as file under /app repository (or at any location of your preference).
    #! /bin/bash
    table=(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 - _ =)
    read text
    # breaking binary represantation of $text in to 6-bit blocks
    for line in $(echo -n "$text" | xxd -b -g 0 | cut -d ' ' -f 2 | paste -s -d '' | fold -w 6 -s)
        length=$(echo ${#line})
        let padding=6-$length
        # padding 6-bit to 8-bit by adding zeros to the right
        if (($padding > 0)); then
            while ((${#p} < "$padding")); do
        # convert binary to decimal
        n=$(echo "ibase=2;$line$p" | bc)
        # output the table looked up character
        echo -n ${table[n]}

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!