一、有问题的shell脚本
#!/bin/bash
#--------------------------------------------------
#Author:jacky
#FileName:truncatetable.sh
#Function:
#Version:1.0
#Created:2017-09-22
#--------------------------------------------------
HOSTNAME="htvdb01" #数据库信息
PORT="3306"
USERNAME="root"
PASSWORD="htvdasd"
DBNAME="db01" #数据库名称
currdate=$(date +%Y%m%d)
logdir=`pwd`
logfile=$logdir/${currdate}log
tmptable="tmptable.sql"
deltables="tablesname.conf"
function deltablesql ()
{
if [ -f $tmptable ];then
rm -rf $tmptable
fi
while read line
do
echo "TRUNCATE TABLE $line;" >>$tmptable
done<$deltables
}
function deltable ()
{
nums=`cat $tmptable|wc -l`
for ((i=1;i<=$nums;i++))
do
echo "[num:$i] `date`" >> $logfile
cat $tmptable|mysql -h ${HOSTNAME} -P${PORT} -u${USERNAME} -p${PASSWORD} -D${DBNAME}
if [[ $? = 0 ]]
then
echo "$tmptable success" >> $logfile
else
echo "$tmptable false" >> $logfile
fi
done
exit 0
}
deltablesql
deltable