Im writing a script the i add later as a cronjob, so this script has functions and inside it uses a here document to execute commands on remote server
there is a variabe "result" in this script that will tel the state of the hosts
I need the same variable "result" to echo outside of the here document (EOF)
How do i do this
one(){
ssh_cmd="$(cat <<-EOF
echo --------------------------------------------------------------
echo "Checking testapp Status on Domain Controller --> host = slave1 "
echo --------------------------------------------------------------
result=(\$(/opt/jboss/web/bin/jboss-cli.sh --connect controller=10.0.0.4:9990 --commands='ls /host=slave1/server-config=testapp' | grep 'status=' | awk 'FNR%2' | sed -r 's/.{7}//'))
echo ----------------
echo "\${result[@]}"
echo ----------------
if [ "\${result[@]}" != "STARTED" ];
then
echo --------------------------------------
echo "Starting the server"
echo --------------------------------------
/opt/jboss/web/bin/jboss-cli.sh --connect controller=10.0.0.4:9990 --commands='/host=slave1/server-config=testapp:start'
else
echo --------------------------------------
echo "Server is running"
echo --------------------------------------
fi
EOF
)"
ssh -t root@someserver "$ssh_cmd"
}
echo $result
if [ $result == value];
then
two (run function two)
else
exit