Thursday, May 18, 2017

Use ballerina to extend your bash scripts capabilities

Ballerina provides a comprehensive collection of connectors that can be used to work with popular services such as twitter, gmail and facebook. They are easy to use and comes bundled in a lean distribution(what is 15mb these days?) When coupled with its integration excellence it can solve many integration challenges in a way that was not possible before.

Ballerina can also become a useful tool for DevOps engineers who welcome the challenge of learning a new language. The example below shows how a ballerina script that uses the twitter API can be embedded into a shell script. Similarly you can avail any one of the ballerina connectors listed here[1].

#!/bin/bash
MSG="WSO2 Ballerina goes well with shell.."
ballerina_utility_function()
{
BALLERINA_SCRIPT_LOCATION="$BALLERINA_HOME/samples/twitterConnector/twitterConnector.bal"
bash "$BALLERINA_HOME/bin/ballerina" "run" "main" "$BALLERINA_SCRIPT_LOCATION" "$1" "$2" "$3" "$4" "$MSG"
return
}
RESPONSE="$(ballerina_utility_function $1 $2 $3 $4 $MSG)"
echo "-----> $RESPONSE"


Execute the script as follows,

 ./script.sh <consumerKey> <consumerSecret> <accessToken> <accessTokenSecret>


Look to the ballerina 0.8X twitter connector sample readme for further instructions. Find out more about ballerina here: http://ballerinalang.org


[1] - http://ballerinalang.org/docs/api/0.8/

Note: this example was written for ballerina 0.86 and may not work with other versions. 

No comments:

Post a Comment