#!/bin/sh
for j in `mysql -uroot -e "USE spservice;SHOW TABLES" | grep -v Tables`
do
case $j in
mo_log|mt_log|report_info)
:
;;
*)
mysqldump -uroot --default-character-set=gbk --opt spservice $j >> $j.sql
esac
done
>>表名不固定 #!/bin/sh
for j in `mysql -uroot -e "USE spservice;SHOW TABLES" | grep -v Tables`
do
for i in "$@"
do
if [ $j != $i ];then
mysqldump -uroot --default-character-set=gbk --opt spservice $j >> $j.sql
fi
done
done
>>更简洁的方法
#!/bin/sh
for j in `mysql -uroot -e "USE spservice;SHOW TABLES" | grep -v Tables`
do
echo $@ | grep -wq "<$j>"
if [ $? -ne 0 ];then
mysqldump -uroot --default-character-set=gbk --opt spservice $j >> $j.sql
fi
done
>>使用方法
sh exclude.sh mo_log mt_log report_log
#定义一个shell数组
tables=(mo_log mt_log report_log)
sh exclude.sh ${tables[@]}
2014-07-13 16:31:12