mysql - Bash - get a reverse count of loop in output -


i want count of loop in reverse in output know how many loop remaining miss finish.

#!/bin/bash datenow=$(date +"%f") logfile="table-"$datenow".log" rm -f table.sql mysql --login-path=myloginpath -h xhost -n -e \ "select count(*) database.table a.field = 0;" | tee -a     $logfile mysqldump --login-path=myloginpath-h xhost database table > table.sql read -p "insert host separated comma ',' : " localcs mysql --login-path=myloginpath -h xhost -n -e \ "select n.ipaddress database.hosts n n.hosts in ($localcs);"  > ip.txt ip in $(cat ip.txt); mysql --login-path=myloginpath -h $ip "database" < "table.sql" echo $ip  | tee -a $logfile && mysql --login-path=myloginpath -h $ip -n -e \ "select count(*) database.table a.field = 0;" | tee -a $logfile done 

something this:

100 (mysql output) 99 (mysql output) 98 (mysql output) ..... 

you need know how many lines in stream in advance.

num=$(wc -l < ip.txt) while read -r ip;     # work, use $num needed      # decrement num     num=$((num-1)) done < ip.txt 

by way, shows recommended way of iterating on file; don't use for loop.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -