#!/bin/bash
echo begin
echo ==============

HOSTNAME="127.0.0.1"
PORT="3306"
USERNAME="root"
PASSWORD="123456"
DBNAME="simba-yunda-sorter-database"
TBNAME="tb_sort_result"
if [ ! -f in.txt ];then
	echo "file not found"
	exit 1;
fi
cat in.txt | sed '/^$/d' | sed 's/[[:space:]]//g'> /tmp/in.tmp
cat /dev/null > out.txt
for barcode in `cat /tmp/in.tmp`;do
	echo "条码:${barcode}"
	db_sql="SELECT barcode,carId,platId,destinationCode,droppedSlot,recordDate FROM ${TBNAME} WHERE barCode = ${barcode} ;"
	mysql -h${HOSTNAME} -P${PORT} -u${USERNAME} -p${PASSWORD} ${DBNAME} -e "${db_sql}" > /tmp/dbdate.tmp
	sed -i "1d"  /tmp/dbdate.tmp
	sed -i "2,$ s/^/xxxxxxxxxxxxx\t/g" /tmp/dbdate.tmp
	echo -e "${barcode}\t$(cat /tmp/dbdate.tmp)" >> out.txt
done
rm -rf /tmp/in.tmp /tmp/dbdate.tmp
exit 0;

