Compare a variable that can have numeric or string as value
- by Tarun
I have a variable named Seconds_Behind_Master from one of my scripts. The problem is that this variable can either have a numeric value or can also take a string NULL as its value. Now, when I try to execute this script in shell it gets executed but gives a warning like this:
[: Illegal number: NULL
I believe it is due to the fact that in this case the value is NULL but when it compares it with numeral value 60 it gives this warning. How can I rectify it?
Here is the piece of code:
Seconds_Behind_Master=$Show_Slave_Status | grep "Seconds_Behind_Master" | awk -F": " {' print $2 '}
if [ "$Seconds_Behind_Master" -ge "60" ]; then
echo "replication delayed greater than or equal to 60."
else
if [ "$Seconds_Behind_Master" = "NULL" ]; then
echo "Delay is Null."
fi
fi