two log file comparison and display if needed...

Hi All,

i've written script to collect the tablespaces and the datafiles related to each tablespaces with free space available and directed to two logfiles.. ( pasted below)

  1. datafile_test.log
    PSAPSR3
    PSAPSR3700
    PSAPSR3USR

  2. freedata_test.log
    /oracle/PJ1/sapdata3/sr3_14/sr3.data14 PSAPSR3 640
    /oracle/PJ1/sapdata3/sr3_14/sr3.data14 PSAPSR3 114624
    /oracle/PJ1/sapdata1/sr3700_1/sr3700.data1 PSAPSR3700 50112
    /oracle/PJ1/sapdata1/sr3700_2/sr3700.data2 PSAPSR3700 33728
    /oracle/PJ1/sapdata1/sr3700_3/sr3700.data3 PSAPSR3700 14272
    /oracle/PJ1/sapdata1/sr3700_4/sr3700.data4 PSAPSR3700 17344
    /oracle/PJ1/sapdata2/sr3700_5/sr3700.data5 PSAPSR3700 15296
    /oracle/PJ1/sapdata2/sr3700_6/sr3700.data6 PSAPSR3700 256
    /oracle/PJ1/sapdata2/sr3700_7/sr3700.data7 PSAPSR3700 1984
    /oracle/PJ1/sapdata2/sr3700_8/sr3700.data8 PSAPSR3700 960
    /oracle/PJ1/sapdata3/sr3700_10/sr3700.data10 PSAPSR3700 3008
    /oracle/PJ1/sapdata3/sr3700_11/sr3700.data11 PSAPSR3700 960
    /oracle/PJ1/sapdata3/sr3700_12/sr3700.data12 PSAPSR3700 960
    /oracle/PJ1/sapdata3/sr3700_9/sr3700.data9 PSAPSR3700 960
    /oracle/PJ1/sapdata4/sr3700_13/sr3700.data13 PSAPSR3700 6080
    /oracle/PJ1/sapdata4/sr3700_14/sr3700.data14 PSAPSR3700 9152
    /oracle/PJ1/sapdata4/sr3700_15/sr3700.data15 PSAPSR3700 30656
    /oracle/PJ1/sapdata4/sr3700_16/sr3700.data16 PSAPSR3700 52160
    /oracle/PJ1/sapdata1/sr3usr_1/sr3usr.data1 PSAPSR3USR 11968

Now i want to write a script which need to take the first tablespace name from log 1 and then grep that tablespace in log 2 and search if any of the datafile is having less than 6000 mb then "echo .." And then take second tablespace name from log 1 and repeat the same...

Any help is appreciated..

grep -f datafile_test.log freedata_test.log| awk '$3 < 6000 {print $1}'

Assuming your 3rd column is in MB.

awk '{ if (FNR==NR) { a[$2]+=$3; next } if (a[$1] < 6000) { print $1 } }' freedata_test.log datafile_test.log

Use nawk or /usr/xpg4/bin/awk on Solaris.
I would do it all in sql though ...

awk 'NR == FNR { tbs[$1]; next }
$2 in tbs && $NF < 6000 {
  printf "tablespace %s, datafile %s has %d MB free\n",
    $2, $1, $NF
  }' datafile_test.log freedata_test.log

The OP said:

But, of course, your idea makes more sense.

Thanks for the correction

perl:

@arr=('PSAPSR3','PSAPSR3700','PSAPSR3USR');
open FH,"<a.txt";
while(<FH>){
	@_= split(" ",$_);
	map {tr/\n//d} @_;
	$_{$_[1]}.=$_ if ($_[2]<6000);
}
close FH;
for($i=0;$i<=$#arr;$i++){
	print $_{$arr[$i]},"\n";
}