i want to connect to 4 servers via bashscript and execute on each server some commands. The output of the commands should be saved in a variable locally. So i tried this peace of code.
I've already tried several things. When i just execute an "ls" or something else, i get the right result. Only with zgrep/grep it does not work like expected. The script stops after the 4th echo. So it looks like there is any problem with the grep command, but i dont have any clue what.
for node in $(echo $nodes | sed "s/,/ /g")
do
echo "############################"
echo "Searching in Node: $node"
echo "Searching in file(s) of pattern: $FILENAME"
echo "Searching for string: $SEARCH_STRING"
OUT=$(ssh -t -v $user@$node "cd $TESA_LOG_DIR; zgrep $SEARCH_STRING $FILENAME")
echo $OUT
done