Wednesday, February 10, 2016

on fly Variable substitution

This is quite old case I had been using for long, but never blogged as it has security risk if not handled properly use of eval.

Using wide range of hosts services on distributed cluster it can be helpful.

Say we have list of hosts running different services, and you need to connect for particular reason the

Say we alias the list of hosts running services on different clusters,
  • e.g. cluster: 
    • ALPHA, BETA
  • services: 
    • FALCON, OOZIE


so we have aliases, host and services
ALPHA_FALCON_HOST=alpha001.my.home.net
ALPHA_OOZIE_HOST= alpha002.my.home.net
BETA_FALCON_HOST=beta1001.my.home.net
BETA_OOZIE_HOST=beta402.my.home.net


RANGE_HOST=beta402.my.home.net
we have aliases, service with port to access the service correctly
OOZIE_URL=’http://$OOZIE_HOST:11000/oozie’FALCON_URL=’http://$FALCON_HOST:15000’ 


Now we want to access BETA cluster OOZIE_HOST, and set the URL accordingly
setting two set of variables on fly to access there service,
OOZIE_HOST=$BETA_OOZIE_HOSTOOZIE_URL=`echo "$(eval echo $OOZIE_URL )"`


e.g. might be bad if you have few services,
but its very helpful if we have large cluster farm, and have proper aliasing