I work on Teradata database and have a space check script. Script is supposed to raise flag as CRITICAL or WARNING depending on space usage values defined at start of the script.
My sample SQL file output is (DatabaseOutput.log) file is as below, this file is used as input to awk block.
### Some multiline Database query, resulting in Database Space usage
*** Query completed. 11 rows found. 4 columns returned.
*** Total elapsed time was 11 seconds.
## Output of the query, I am interested in DatabaseName, Perc2, MaxPerm
DatabaseName Perc Perc2 MaxPerm
---------------------------------------------------- ---------------------- ------- -----------
AAA 9.21899768137583E-001 92.19 10102320
BBB 9.19923819717036E-001 91.99 524160
CCC 9.17517791271651E-001 91.75 1687440
DDD 9.15820363471060E-001 91.58 816720
EEE 9.09293748338489E-001 90.93 149760
FFF 9.07840905921109E-001 90.78 6934080
GGG 9.04946085680591E-001 90.49 7273440
HHH 8.54498111733230E-001 85.45 2538960
III 8.22783559253080E-001 82.28 7598400
JJJ 8.02181524253446E-001 80.22 8077680
+---------+---------+---------+---------+---------+---------+---+---------+-
Required output is
WARNING AAA 92.19 10102320
WARNING BBB 91.99 524160
WARNING CCC 91.75 1687440
WARNING DDD 91.58 816720
WARNING EEE 90.93 149760
WARNING FFF 90.78 6934080
WARNING GGG 90.49 7273440
I have working awk code which takes three passes.. Can it be reduced to one awk pass?
Working awk code :
cLvlCRIT=95
cLvlWARN=90
cat DatabaseOutput.log |
awk '/-------------------/,/^$/' | # captures output block; it excludes query, logon, logoff information and header line but keeps separator's line.
awk '{if (NR >= 2) {print}}' | # removes separator line, prints all lines from line 2 to EOF
awk -v lLvlCRIT=$cLvlCRIT -v lLvlWARN=$cLvlWARN ' {
if ( $1 != "StartCapture" && $3 >= lLvlCRIT ) {
printf("%11s%30s%10s%10s\n", "CRITICAL",$1,$3,$4)
}
if ( $1 != "StartCapture" && $3 >= lLvlWARN && $3 < lLvlCRIT ) {
printf("%11s%30s%10s%10s\n", "WARNING",$1,$3,$4)
}
} '
Thanks in advance !