script is running but don’t know where it is stuck

Here is my script where I have used nested loop.
But wen I was trying to print value in inner loop its not printing anything.
Its not enter into first loop.
Please look into this.

CURR_DIR=`dirname $0`
SCRIPT_DIR=`pwd`
echo "Current Directory: $CURR_DIR"
source ${CURR_DIR}/db.conf
mysql --batch --raw -u $DB_USER -p$DB_PASS -h $DB_HOST $MYDB -e'SELECT dc_id,dc_name from `dc_mast`'|awk '{print $1 "," $2 "n"}'>${CURR_DIR}/datac.txt
sed -i -e "1d" ${CURR_DIR}/datac.txt
sed -i -e '/^$/d' ${CURR_DIR}/datac.txt
echo "outer first loop"
while IFS="," read dc_id dc_name
do
  echo ${dc_id} 
  echo "inner first loop" ${dc_id}
  mysql --batch --raw -u $DB_USER -p$DB_PASS -h $DB_HOST $MYDB -e'SELECT distinct c.cl_id as cl_id,c.cl_dns as cl_dns FROM cso_crm.cluster_mast c join cso_crm.env_detail e on e.cl_id=c.cl_id join cso_crm.env_mast m on m.env_id=e.env_id where m.dc_id='${dc_id}' and m.service_id='1' and e.app_id='2'' | awk '{print $1 "," $2 "n"}' > ${CURR_DIR}/cl.txt

  sed -i -e "1d" ${CURR_DIR}/c1.txt
  sed -i -e '/^$/d' ${CURR_DIR}/c1.txt

  while IFS="," read cl_id cl_dns
  do
    echo "inner second loop" ${cl_id}
    mysql --batch --raw -u $DB_USER -p$DB_PASS -h $DB_HOST $MYDB -e'select c.cust_name as customer from cluster_mast m inner join env_detail d on m.cl_id =d.cl_id join env_mast e on d.env_id = e.env_id join cust_mast c on e.cust_id = c.cust_id where m.cl_id='${cl_id}' and e.status=1' | awk '{print $1 "n"}'> ${CURR_DIR}/cname.txt
    sed -i -e "1d" ${CURR_DIR}/c1.txt
    sed -i -e '/^$/d' ${CURR_DIR}/c1.txt

    while IFS="," read customer
    do
    echo "https://"${cl_dns}"/"${cust_name} > ${CURR_DIR}/xxx_url.txt
    done
    rm cname.txt
  done
  rm c1.txt
done


Source: shell

Leave a Reply