bash script with sql to get the number of records from multiple tables.

Here is the bash script:

#!/bin/sh
names[1]=errorlog
names[2]=amit1log
names[3]=amit2log
names[4]=amit3log
names[5]=amit4log
j=1
echo $1
for i in $( sqlplus amit/passwd@tns @get_count.sql |sed  -n \’/COUNT/,/Disconnected/p\’|sed \’/COUNT/ d\’|sed \’/—/ d\’|sed \’/Disconnected/ d\’|tr \’n\’ \’ \’  )
do
temp=${names[$j]}
let count=30-${#temp}
for ((I=1; I <= $count ; I++))
do
printf \” \”
done
echo  \”${names[$j]}    : $i\”
# echo $j
let j=j+1
done
echo
echo

and the required sql script:

select count(*) from errorlog;
select count(*) from amit1log;
select count(*) from amit2log;
select count(*) from amit3log;
select count(*) from amit4log;
quit;

I have verified this to be working on Solaris and Oracle. Might need some changes for mysql, but should not be much.

\"\"

About Amit Agarwal

1 Trackback on “bash script with sql to get the number of records from multiple tables.”