-1

我有一个查询导致以下数据

询问 :

db2 "select RTRIM(substr(A.TBSP_NAME,1,30)),A.TBSP_FREE_PAGES as FREE,B.CONTAINER_NAME as CON_PATH from SYSIBMADM.TBSP_UTILIZATION A ,SYSIBMADM.CONTAINER_UTILIZATION B where A.TBSP_ID=B.TBSP_ID and A.TBSP_AUTO_RESIZE_ENABLED=0 with UR"

结果 :

1                              FREE                 CON_PATH                                                                                                                                                                                             
 ------------------------------ -------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 USERSPACE1                                    14736 /adrst/bdts/userspc_container                                                                                                                                                                        
 USERSPACE1                                    14736 /adrst/bdts/userspc_container1                                                                                                                                                                       
 MASTER                                         3472 /adrst/bdts/master_container                                                                                                                                                                         
 TRANS_DATA                                     1200 /adrst/bdts/trans_data_container                                                                                                                                                                     
 MASTER_INDEX                                   1840 /adrst/bdts/master_index_container                                                                                                                                                                   
 TRANSACTION_INDEX                               960 /adrst/bdts/transaction_index_container                                                                                                                                                              
 TEMP_SYS                                       2192 /adrst/bdts/temp_sys_container                                                                                                                                                                       
 AUDIT_DATA                                     3360 /adrst/bdts/audit_data_container                                                                                                                                                                     
 TEMP_USR                                       2672 /adrst/bdts/temp_usr_container                                                                                                                                                                       
 TSASNCA                                        2840 /home/db2inst1/db2inst1/NODE0000/SQL00002/TSASNCA                                                                                                                                                    
 TSASNUOW                                       2880 /home/db2inst1/db2inst1/NODE0000/SQL00002/TSASNUOW                                                                                                                                                   
 TSASNAA                                        3712 /home/db2inst1/db2inst1/NODE0000/SQL00002/TSASNAA                                                                                                                                                    
 TSCDADDRESSMASTER                              2048 /home/db2inst1/db2inst1/NODE0000/SQL00002/CDADDRESSMASTER                                                                                                                                            

   13 record(s) selected.

现在我正在编写一个脚本,它采用第 2 列并进行比较,如果 < 1000 那么我们在打印中提到 col1 和 col2

所以我写的脚本是

#!/usr/bin/perl
use strict;
use warnings;


`db2 "connect to awdrt"`;
my @tbsp= grep /([a-zA-Z_]*)\s*([0-9]*)\s*([a-zA-Z_]*)/,`db2 "select RTRIM(substr(A.TBSP_NAME,1,30)),A.TBSP_FREE_PAGES as FREE,B.CONTAINER_NAME as CON_PATH from SYSIBMADM.TBSP_UTILIZATION A ,SYSIBMADM.CONTAINER_UTILIZATION B where A.TBSP_ID=B.TBSP_ID and A.TBSP_AUTO_RESIZE_ENABLED=0 with UR"`;

print "@tbsp";

我已经给出了打印来测试我成功地消除了'-----'第一行和最后一行......这样我就可以拆分并初始化为 3 个变量并在 foreach 循环中进行计算,但是某处出错........帮助表示赞赏

4

3 回答 3

0

我得到了我问的问题的解决方案......

#!/usr/bin/perl
use strict;
use warnings;


my $good = "\[\033[32mOK\033[0m\]";
my $bad = "\[\033[31m!!\033[0m\]";


`db2 "connect to awdrt"`;
my @tbsp= grep /\//,`db2 "select RTRIM(substr(A.TBSP_NAME,1,30)),A.TBSP_FREE_PAGES as FREE,B.CONTAINER_NAME as CON_PATH from SYSIBMADM.TBSP_UTILIZATION A ,SYSIBMADM.CONTAINER_UTILIZATION B where A.TBSP_ID=B.TBSP_ID and A.TBSP_AUTO_RESIZE_ENABLED=0 with UR"`;

foreach (@tbsp){
chomp;
s/^\s*//;
s/\s*$//;
my ($col1,$col2,$col3)=split /\s+/,$_,3;
if ($col2 <= 2000){
print "$bad $col1 has $col2 pages with container $col3\n";
#print "alter tablespace $col1 extend (file \'$col3\' 1000)\n";
}
}

它工作正常........谢谢大家

于 2013-03-08T13:48:01.840 回答
0
# loop over the query output
for (`db2 "select ...`) {
  if (my ($c0, $c1, $c2) = /(\w+)\s*(\d+)\s*([\w\/]+)/) {
    print "$c0,$c1,$c2\n";
  }   
}   
于 2013-03-08T06:53:26.460 回答
0

您可以在单个 grep 中包含对 FREE > 1000 的行的过滤,如下所示:

#!/usr/bin/perl
use strict;
use warnings;

my @lines = <DATA>;

my @filtered = grep {/(\S+) # non-space characters
              \s+ # one or more spaces
              (\d+) # numeric characters
              \s+ # one or more spaces
              (\S+) # non-space characters
             /x,
               $2 > 1000 # filter by FREE > 1000
             } @lines;

换句话说,首先使用正则表达式过滤数据行,然后只返回 FREE > 1000 的行。

于 2013-03-08T13:33:49.300 回答