Reputation: 27
Here in the below lines of code, which is designed to iterate through a list of API names from a dynamic file "$$_EFFECTIVE_JARS_LIST_T" and perform some activity. Now the problem is not in the logic, but in the echo.
The TEST1 in the first test echo is not getting printed. Also, you can see some text is appearing in the promt area after the execution of script. Because of this, i am unable to parse the output of this logic. I am trying to print a JSON which is not getting created properly because of this grambled output.
{
declare -a SB_IPS=(
"127.0.0.1"
);
loop=0;
_PRESENT=0;
APIStat="";
p="";
# while IFS='
#' read -r API_NAME || [ -n "$API_NAME" ]
cat $$_EFFECTIVE_JARS_LIST_T | while read -r API_NAME;
do
echo -e "TEST1 =================== ${API_NAME} =================";
((loop++));
APIStat='';
for SB_IP in "${SB_IPS[@]}"
do
_PRESENT=` cat $$_PROCESS_LIST_T | grep "/${API_NAME}" | grep ${SB_IP} | wc -l `;
if [ "${_PRESENT}" -eq 0 ]
then
APIStat="${APIStat},-";
elif [ "${_PRESENT}" -eq 1 ]
then
_path=`cat $$_PROCESS_LIST_T | grep "/${API_NAME}" | grep ${SB_IP} | awk -F" " {'print $NF'}`;
#API_DATA=`getAPIData ${SB_IP} ${_path}`;
APIStat="${APIStat},X";
fi
APIStat=`echo ${APIStat} | sed 's/^,//g'`;
done
echo "TEST2 =================== ${APIStat} =================";
#echo "${API_NAME},${APIStat}" | awk -F, '{print "{\"APIName\":\"" $1 "\",\"RAM\":" $2",\"Core\":"$3",\"KernelVersion\": \""$4"\"},"}' >> ${LOG_FILE_WITH_PATH};
echo -n "${API_NAME}";
# echo -n "${API_NAME},${APIStat}" | awk -F, '{print "{\"APIName\":\"" $1 "\",\"APIStat\":" $2"},"}';
done;
}
Upvotes: -3
Views: 23
Reputation: 27
Looks like i have a \r character in the input file. Hence the moment i print the API_NAME, the rest of the line gets printed in the next line. When the loop goes through the next iteration, the previously printed line gets over written.
To solve this, i have remove the "\r" char in the API_NAME.
tr -d '\r'
Upvotes: 0