【发布时间】:2015-04-22 14:48:08
【问题描述】:
我想在输出中反向计算循环数,以了解我错过完成的剩余循环数。
#!/bin/bash
datenow=$(date +"%F")
logfile="table-"$datenow".log"
rm -f table.sql
mysql --login-path=myloginpath -h xhost -N -e \
"select count(*) from database.table a where a.field = 0;" | tee -a $logfile
mysqldump --login-path=myloginpath-h xhost database table > table.sql
read -p "Insert Host Separated by comma ',' : " localcs
mysql --login-path=myloginpath -h xhost -N -e \
"select n.ipaddress from database.hosts n where n.hosts in ($localcs);" > ip.txt
for ip in $(cat ip.txt);
do
mysql --login-path=myloginpath -h $ip "database" < "table.sql"
echo $ip | tee -a $logfile && mysql --login-path=myloginpath -h $ip -N -e \
"select count(*) from database.table a where a.field = 0;" | tee -a $logfile
done
类似这样的:
100
(mysql output)
99
(mysql output)
98
(mysql output)
.....
【问题讨论】:
-
这个脚本有多少实际上与问题相关?您是否只想遍历
ip.txt的行并打印一个递减的数字?