Created time: 2014-10-24 Last updated time:

The shell command frequently used when building cloud

When we build the cloud environment to run applications on it, we have to write shell scripts. In this blog entry, I'm going to write frequently used technique of the shell script.

Java programmers has little opportunity to write shell script, but such opportunities are increasing these days. But if we learn some technique, we can almost freely handle the shell script and build the environment of the cloud.

Replace environment variables

Following function is to gathering environment variables to replace, and make regular expression to input into the sed.

This script is used in the Openshift cartridge's shell. The Openshift set up environment variables automatically, so we have to get then and replace the parameters of configuration files. Then I used this script frequently.

Following code is an example code of using the function.

Make the array of files, which is "replacement_conf_files", in the directory "${SRC_CONFIG_PATH}/conf/".

This technique is very useful on building docker's environment. When you use multiple container, or make sharing disk volume to mount the external file system on the container, the environment variables are useful to communicate with the container.

Including external shell script

I'm a Java programmer, so I'm not good at writing shell script. But I think we have to know how to include external shell script defining utility functions, so that we write clean and readable shell script.

Including external script is very easy. Just use "source" command.

Manipulate a line of configuration file

Manipulating a line of configuration file by sed command.

Go to Top