'Is there a way to export a local variable out a ssh session in bash

Basically what I want is export a list of ips from a local file, the question here is that I can't use scp as the ports are blocked from this server to my main server due security policies.

this is the code:

    #!/bin/bash

read -p "Enter IP or Hostname to start the process: " hostname
    echo $hostname

    if [ -z ${hostname} ]; then
        echo "'host' variable is not set"
        exit 1
    fi

    for i in $hostname
    do ssh $i 'redis-cli cluster nodes > /tmp/cluster_check.txt;
    my_var=$(cat /tmp/cluster_check.txt | egrep -w myself |cut -d',' -f 1 |cut -d" " -f 2 |cut -d'@' -f 1 );
    printf "\e[33m"; hostname; printf "\e[0m\n";
    printf "\n\e[33mThis the IP and port you are connected "$my_var".\e[0m\n";
    redis-cli --cluster check $my_var > /tmp/redis_check.txt;
    cd /tmp/;
    host_list=$(cat redis_check.txt| egrep -w M: |cut -d" " -f 3 |cut -d':' -f 1);
    echo "$host_list" > /tmp/master_ips.list;
    printf "this is a list of the Masters on this cluster.\n"
    cat master_ips.list
    '
    done

fist I create a file with name "redis_check.txt" from that file I will extract some Ip's with the variable "$host_list" this creates a local variable with a list of ips this file creates an additional file called "master_ips.list". as I mention the easy way to get these values is exporting the master_ips.list to my main server but the port for scp is locked and I can't change that, but also these values are stored on the local server when I run the ssh session, but if I cut the loop this variables cant be reached, any suggestion to get that variable ($host_list) values out of this local server to my main server.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source