<commit_before>#!/bin/bash -e

#############
# CONSTANTS #
#############

SSH_CONNECTION_ATTEMPTS='5'
SSH_CONNECTION_TIMEOUT_IN_SECONDS='10'

##################
# IMPLEMENTATION #
##################

function displayUsage()
{
    local -r scriptName="$(basename "${BASH_SOURCE[0]}")"

    echo -e '\033[1;33m'
    echo    'SYNOPSIS :'
    echo    "  ${scriptName}"
    echo    '    --help'
    echo    '    --identity-file    <IDENTITY_FILE>'
    echo    '    --login-name       <LOGIN_NAME>'
    echo    '    --commands         <COMMANDS>'
    echo    '    --addresses        <ADDRESSES>'
    echo -e '\033[1;35m'
    echo    'DESCRIPTION :'
    echo    '  --help             Help page (optional)'
    echo    '  --identity-file    Path to identity file (optional)'
    echo    '  --login-name       Login name (optional)'
    echo    '  --commands         Commands that will be run in remote servers (require)'
    echo    '  --addresses        Server addresses seperated by spaces or commas (require)'
    echo -e '\033[1;36m'
    echo    'EXAMPLES :'
    echo    "  ./${scriptName} --help"
    echo    "  ./${scriptName} --commands 'date' --addresses '192.168.127.12, 172.16.17.32'"
    echo    "  ./${scriptName} --identity-file '/path/to/key.pem' --login-name 'ec2-user' --commands 'ntpstat' --addresses '192.168.127.12, 172.16.17.32'"
    echo    "  ./${scriptName} --identity-file '/path/to/key.pem' --login-name 'ec2-user' --commands 'chronyc tracking' --addresses '192.168.127.12, 5.6.7.7'"
    echo -e '\033[0m'

    exit "${1}"
}

function runCommands()
{
    local -r identityFile="${1}"
    local -r loginName="${2}"
    local -r commands="${3}"
    local -r addresses=("${@:4}")

    # Built Prompt

    local -r prompt='echo -e "\033[1;36m<\033[31m$(whoami)\033[34m@\033[33m$(hostname)\033[36m><\033[35m$(pwd)\033[36m>\033[0m"'

    # Get Identity File Option

    local identityOption=()

    if [[ "$(isEmptyString "${identityFile}")" = 'false' && -f "${identityFile}" ]]
    then
        identityOption=('-i' "${identityFile}")
    fi

    # Machine Walker

    local address=''

    for address in "${addresses[@]}"
    do
        header "${address}"

        if [[ "$(isEmptyString "${loginName}")" = 'true' ]]
        then
            ssh "${identityOption[@]}" \
                -o 'IdentitiesOnly yes' \
                -o "ConnectionAttempts ${SSH_CONNECTION_ATTEMPTS}" \
                -o "ConnectTimeout ${SSH_CONNECTION_TIMEOUT_IN_SECONDS}" \
                -n "${address}" "${prompt} && ${commands}"
        else
            ssh "${identityOption[@]}" \
                -o 'IdentitiesOnly yes' \
                -o "ConnectionAttempts ${SSH_CONNECTION_ATTEMPTS}" \
                -o "ConnectTimeout ${SSH_CONNECTION_TIMEOUT_IN_SECONDS}" \
                -n "${loginName}@${address}" "${prompt} && ${commands}"
        fi
    done
}
<commit_msg>bug fixes<commit_after>#!/bin/bash -e

#############
# CONSTANTS #
#############

SSH_CONNECTION_ATTEMPTS='3'
SSH_CONNECTION_TIMEOUT_IN_SECONDS='5'

##################
# IMPLEMENTATION #
##################

function displayUsage()
{
    local -r scriptName="$(basename "${BASH_SOURCE[0]}")"

    echo -e '\033[1;33m'
    echo    'SYNOPSIS :'
    echo    "  ${scriptName}"
    echo    '    --help'
    echo    '    --identity-file    <IDENTITY_FILE>'
    echo    '    --login-name       <LOGIN_NAME>'
    echo    '    --commands         <COMMANDS>'
    echo    '    --addresses        <ADDRESSES>'
    echo -e '\033[1;35m'
    echo    'DESCRIPTION :'
    echo    '  --help             Help page (optional)'
    echo    '  --identity-file    Path to identity file (optional)'
    echo    '  --login-name       Login name (optional)'
    echo    '  --commands         Commands that will be run in remote servers (require)'
    echo    '  --addresses        Server addresses seperated by spaces or commas (require)'
    echo -e '\033[1;36m'
    echo    'EXAMPLES :'
    echo    "  ./${scriptName} --help"
    echo    "  ./${scriptName} --commands 'date' --addresses '192.168.127.12, 172.16.17.32'"
    echo    "  ./${scriptName} --identity-file '/path/to/key.pem' --login-name 'ec2-user' --commands 'ntpstat' --addresses '192.168.127.12, 5.6.7.7'"
    echo    "  ./${scriptName} --identity-file '/path/to/key.pem' --login-name 'ec2-user' --commands 'chronyc tracking' --addresses '192.168.127.12, 5.6.7.7'"
    echo -e '\033[0m'

    exit "${1}"
}

function runCommands()
{
    local -r identityFile="${1}"
    local -r loginName="${2}"
    local -r commands="${3}"
    local -r addresses=($(sortUniqArray "${@:4}"))

    # Built Prompt

    local -r prompt='echo -e "\033[1;36m<\033[31m$(whoami)\033[34m@\033[33m$(hostname)\033[36m><\033[35m$(pwd)\033[36m>\033[0m"'

    # Get Identity File Option

    local identityOption=()

    if [[ "$(isEmptyString "${identityFile}")" = 'false' && -f "${identityFile}" ]]
    then
        identityOption=('-i' "${identityFile}")
    fi

    # <NAME>er

    local address=''

    for address in "${addresses[@]}"
    do
        header "${address}"

        if [[ "$(isEmptyString "${loginName}")" = 'true' ]]
        then
            ssh "${identityOption[@]}" \
                -o 'IdentitiesOnly yes' \
                -o "ConnectionAttempts ${SSH_CONNECTION_ATTEMPTS}" \
                -o "ConnectTimeout ${SSH_CONNECTION_TIMEOUT_IN_SECONDS}" \
                -n "${address}" "${prompt} && ${commands}" || true
        else
            ssh "${identityOption[@]}" \
                -o 'IdentitiesOnly yes' \
                -o "ConnectionAttempts ${SSH_CONNECTION_ATTEMPTS}" \
                -o "ConnectTimeout ${SSH_CONNECTION_TIMEOUT_IN_SECONDS}" \
                -n "${loginName}@${address}" "${prompt} && ${commands}" || true
        fi
    done
}

{'fraction_non_alphanumeric': 0.19078149367527292, 'fraction_numerical': 0.04332004851845434, 'mean_word_length': 2.1960132890365447, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 12, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6487888', 'n_tokens_mistral': 2091, 'n_tokens_neox': 1914, 'n_words': 413}