Search code examples
bashelasticsearchcentoskibanamkdir

passing multiple functions to remote shell/ mkdir cannot find directory


I am writing a BASH script capable of deploying, and configuring, an entire elasticsearch cluster. Currently I have two installer scripts, and the config script that handles all SSH logic and the security configuration.

Everything seems to work perfectly except for two functions.

    echo "Transmitting functions and arrays for remote execution!"
    ssh -T "root@$kbip" <<-LIMITBREAK
        eval `typeset -p kibConfigSer`
        eval `typeset -p kibConfigChan`
        eval `typeset -p esip`
        `declare -f checkLocalKibanaConfig`; checkLocalKibanaConfig
        `declare -f createDirectories`; createDirectories
    LIMITBREAK
        echo
        echo "Transmitting functions and array for remote execution!"
        ssh -T "root@$allnodes[x]" <<-LIMITBREAK
            eval `typeset -p esConfig`
            `declare -f checkLocalElasticConfig`; checkLocalElasticConfig
            `declare -f createDirectories`; createDirectories
        LIMITBREAK

These are the HEREDOCs I am using to define the functions in the remote shell. Currently the first declare works fine. It is able to pass the array esConfig with all the configuration settings, and the function checkLocalElasticConfig is both defined and is able to access the strings in the array.

However, no matter what I try, the second declare does nothing. The logic checks if the kibana directory/elastic directory is present, and it successfully checks that the certs directory is not present. But when it attempts to execute the mkdir command...

mkdir: Cannot create directory '/etc/directory/certs': No such file or directory

I am completely stumped. I know that etc exists, I know that directory exists, and certs does not exist which this function:

function createDirectories () 
{
    #Checks if ElasticSearch is present
    if [ -d "/etc/elasticsearch" ] 
    then
        if [ -d "/etc/elasticsearch/certs" ] 
        then
            echo "Directory /etc/elasticsearch/certs exists." 
        else
            echo "/etc/elasticsearch/certs in ElasticSearch does not exist! Making directory!"
            mkdir "/etc/elasticsearch/certs"
        fi
    fi

    #Checks if Kibana is present
    if [ -d "/etc/kibana" ] 
    then
        if [ -d "/etc/kibana/certs" ] 
        then
            echo "Directory /etc/kibana/certs exists." 
        else
            echo "/etc/kibana/certs in Kibana does not exist! Making directory!"
            mkdir "/etc/Kibana/certs"
        fi
    fi
}

should handle.

The purpose of this script is that the createDirectory function is available for local use, and where necessary, is defined for remote use when configuring the cluster nodes.

Any ideas what I am doing wrong? Or what I could be doing better?


Solution

  • Linux is case sensitive. You check if [ -d "/etc/kibana" ] but the mkdir tries to make a directory under /etc/Kibana.