-1

I have a query which result in the following data

Query :

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"

Result :

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.

Now im writing a script which takes the column 2 and compares , if < 1000 then we mention col1 and col2 in print

So the script i have written is

#!/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";

I have given the print to test I am successful in eliminating the '-----' 1'st line and the last line ...so that i can split and initialize to 3 variables and do my calculation in foreach loop , but going wrong somewhere ........Help is appreciated

4

3 に答える 3

0

次のように、FREE > 1000 を持つ行のフィルタリングを単一の grep に含めることができます。

#!/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 に答える
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

私が尋ねた質問に対する解決策を得ました.......

#!/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 に答える