批量删除表

来源:互联网 发布:名扬三角洲淘宝店铺 编辑:程序博客网 时间:2024/06/07 02:23

一、有问题的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}logtmptable="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++))    doecho "[num:$i] `date`" >> $logfile        cat $tmptable|mysql -h ${HOSTNAME}  -P${PORT} -u${USERNAME} -p${PASSWORD} -D${DBNAME}        if [[ $? = 0 ]]then                echo "$tmptable  success" >> $logfileelseecho "$tmptable false" >> $logfilefi    done    exit 0}deltablesqldeltable


原创粉丝点击