I am writing a BASH script that will modify YML files on a local machine. I also want the bash script to also modify these same YML files on remote machines as well.
function checkLocalElasticConfig () {
local tLen=${#esConfig[@]}
echo "\nEnabling Xpack Security!"
sed -i 's/#xpack.security.enabled: false/xpack.security.enabled: true/g' /etc/elasticsearch/elasticsearch.yml
for ((i=0; i<${tLen}; i++));
do
if grep "${esConfig[i]} /etc/elasticsearch/elasticsearch.yml"
then
echo "${esConfig[i]} is already written to config!"
else
echo "\nWriting ${esConfig[i]} to \/etc\/elasticsearch\/elasticsearch\.yml"
echo "${esConfig[i]}" >> /etc/elasticsearch/elasticsearch.yml
fi
done
}
The above function checks the local YML, sees if a setting exists or not, and if it does not, it writes to the file.
I want to be able to recycle the above function by prefixing SSH "root@$variable" so that I can write to remote configs as well, as the remote version is the same. Are there any suggestions anyone might have?