Shell或PERL脚本-基于当前活动表运行多个查询
我希望有人能帮我写shell脚本。我有一个列出不同表前缀的文件 该文件如下所示:Shell或PERL脚本-基于当前活动表运行多个查询,perl,shell,sqlplus,Perl,Shell,Sqlplus,我希望有人能帮我写shell脚本。我有一个列出不同表前缀的文件 该文件如下所示: cat table_names table:1234:nfl table1:2345:nhl table2:5555:nba table3:3355:mls table4:2463:echl 我每周的每一天都有一张不同的桌子 daya dayb dayc dayd daye dayf dayg dayh 我有另一个文件,它告诉我今天的当前表是什么 cat today_table Today's active t
cat table_names
table:1234:nfl
table1:2345:nhl
table2:5555:nba
table3:3355:mls
table4:2463:echl
我每周的每一天都有一张不同的桌子
daya
dayb
dayc
dayd
daye
dayf
dayg
dayh
我有另一个文件,它告诉我今天的当前表是什么
cat today_table
Today's active table is dayf
我试图做的是使用当天的当前活动表查询每个表前缀(table-table4)
以下是我到目前为止的情况:
#!/bin/ksh
active_table=$(today_table|awk '{print $5}')
prefix_table=$(cat table_names|grep -v ^#|awk -F":" '{print $1}'|sort -u)
today=`date "+%Y-%m-%d"`
OutPutDir="/tneal01/SPOOL"
OutPutFile="error"
Execsqlstatement1="select
to_char(current_date,'YYYYMMDD') day,
count(*) Total
from ${prefix_table}.${active_table}
GROUP BY to_char(current_date,'YYYYMMDD')
#adding connection details here
$ORACLE_HOME/bin/sqlplus *********** << Eossql
set lines 80
set pages 50000
set timing on
spool tneal01/SPOOL/counts.`date +%Y-%m-%d`.tmp
$Execsqlstatement1
/
spool off
quit;
Eossql
grep "ORA-" $OutPutDir/$OutPutFile.$today.tmp
if [ $? -eq 0 ]
then
echo "LOG MESSAGE sql select failed"
exit 0
所以spool文件看起来像
dayf table
Monday July 8th
table count =31
table1 count =44
table2 count =33
table3 count =55
table4 count =23
希望我能解释清楚
编辑:我可以用Perl或shell编写。我们将非常感谢这两项建议
谢谢你的阅读
dayf table
Monday July 8th
table count =31
table1 count =44
table2 count =33
table3 count =55
table4 count =23