I am having some problems comparing a variable from a script to the IP address of the system. I have a source file for an app which is not bash fiendly but it has a value set like so
DKUS_MASTER=127.0.0.1
I am fetching that variable in my bash file by doing
DKUSMASTER=`grep "DKUS_MASTER" /root/somestuff.conf | sed 's/DKUS_MASTER=//'`
Here is what i am then doing in my script as i am trying to see if eth0 ip is set to the DKUS_MASTER parameter i am fetching
DKUSMASTER=`grep "DKUS_MASTER" /root/somestuff.conf| sed 's/DKUS_MASTER=//'`
ETH0=$(ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1)
if [ "$ETH0" = "$DKUSMASTER" ]; then
DKUS_STATUS="Master"
else
DKUS_STATUS="Slave"
fi
doing some testing, i can see the variables look correct
echo $DKUSMASTER
echo $ETH0
however, the end status is else false and never true as seen here. In my case the variable $DKUSMASTER does indeed equal to $ETH0, so the status should come back as master.
echo $DKUS_STATUS