I have the following function :
GetHostName () {
NODE01_CHECK=`cat /etc/hosts | grep -w "node01" | awk '{print $1}'`
NODE02_CHECK=`cat /etc/hosts | grep -w "node02" | awk '{print $1}'`
IS_NODE1=`ifconfig -a | grep -w $NODE01_CHECK`
IS_NODE2=`ifconfig -a | grep -w $NODE02_CHECK`
if [[ ! -z $IS_NODE1 ]]; then
echo "This is NODE 1"
fi
if [[ ! -z $IS_NODE2 ]]; then
echo "This is Node 2"
fi
}
This script will identify if a certain ip is configured on one of the two nodes belonging to a cluster. This works fine locally, but I need to run it remotely from a server that only knows of the VIP of the cluster. The goal is to transfer some files to both nodes.
So when I run :
scp -r /tmp/files CLUST_VIP
ssh CLUST_VIP <<EOF
NODE01_CHECK=`cat /etc/hosts | grep -w "node01" | awk '{print $1}'`
NODE02_CHECK=`cat /etc/hosts | grep -w "node02" | awk '{print $1}'`
IS_NODE1=`ifconfig -a | grep -w $NODE01_CHECK`
IS_NODE2=`ifconfig -a | grep -w $NODE02_CHECK`
if [[ ! -z $IS_NODE1 ]]; then
scp -r /tmp/files node02
fi
if [[ ! -z $IS_NODE2 ]]; then
scp -r /tmp/files node01
fi
EOF
However, now while running the same commands in a ssh block, I get the following messages :
Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.
Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.
Pseudo-terminal will not be allocated because stdin is not a terminal.
I have also tried using ssh -t
and that removed the above errors regarding grep
, but the environment variables do not seem to work.
Is there a way to use environment variables over a ssh block?