我想将数据状态信息插入mysql,shell脚本如下:
for intrm in `cat ${intrm_set}`; do
if [ -d ${bazaar_base}/${intrm}/pt=${dt} ]
then
size=`ls -lh ${bazaar_base}/${intrm}/pt=${dt} | grep total | awk '{print $2}'`
count=`wc -l ${bazaar_base}/${intrm}/pt=${dt}/* | grep total | awk '{print $1}'`
lmt=`ls -l --time-style=long-iso ${bazaar_base}/${intrm} | grep pt=2016-03-22 | awk '{print $6,$7}'`
#ls -l --time-style=long-iso ${bazaar_base}/${intrm} | grep pt=2016-03-22 | awk '{print $6,$7}'
echo $dt $intrm $size $count $lmt
else
size='null'
count='null'
lmt='null'
echo $dt $intrm $size $count $lmt
fi
irt_sql='insert into ${tblname}(DATE,INTRM_TBL,SIZE,COUNT,LAST_MODIFIED_TIME) values("${dt}", "${intrm}", "${size}", "${count}", "${lmt}");'
mysql -h${hostname} -P${port} -u${username} -p${password} ${dbname} -e"${irt_sql}"
done
执行时,错误抛出
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '{tblname}(DATE,INTRM_TBL,SIZE,COUNT,LAST_MODIFIED_TIME) values("${dt}", "${intrm' at line 1
但是当我在shell中单独执行insert脚本时,它运行良好。如果出现错误,任何建议都将受到赞赏!
mysql -hhost -Pport \
-uuser -ppasswd dbname \
-e 'insert into monitor_hive_intrm(DATE,INTRM_TBL,SIZE,COUNT,LAST_MODIFIED_TIME) values("0", "0", "0", "0", "0")'