AWK Program Not Executing On Linux with KSH

Overview:
I have an AWK program that parses thru a database backup
server log file and outputs ths following parameters

SRNO DATE : TIME SIZE IN(KB) DATABASE NAME DUMP TYPE
1 May 16 2012: 13:30:00 6874 TestDB database
2 May 16 2012: 13:30:44 11462 master database

Problem:
This program has been tested and works without failure under the bash shell.
however when I try to run this program on a linux server configured to use
the korn shell, the program stops after creating the report headers.

OS Used:

uname -a
Linux apinmslx01 2.6.16.60-0.69.1-default
#1 Fri Sep 17 17:07:54 UTC 2010 i686 i686
i386 GNU/Linux

Shell Used:

echo $0
-ksh

Program Listing:

#BEGIN{tmp="NA";prevback="DAY 00 0000"}
BEGIN{print "SRNO DATE : TIME SIZE IN(KB) DATABASE NAME DUMP TYPE" ;tmp="NA";prevback="DAY 00 0000"}
#NR>2 { delete a[NR-2] }
/DUMP is complete/ {
if(substr($0,1,6)!=substr(prevback,1,6))
{ backupno=1 } # to print backup number of the day
search=" " # split condition
split(a[NR-1],array1,search); # initialise array1, read the previous line and split before DUMP is complete
split($0,array2,search); # initialise array2, read the current line where DUMP is complete
sub ("\\).","",array2[12]); # seperate the database name from current line chg 
sub(":","",array1[9]); # seperate the database name from preivous line
tmp=array1[9]; # assigne database name found on line to tmp
i=2; # initialise the i=2 if we are going to read more previous lines
#print tmp " OUTER " array2[12];# test print case
while(tmp!=array2[12]) # this is extra check if multiple dumps are fired at same time which screwes up backup log
{ # read all previous line untill we get the relevant database line.
split(a[NR-i],array1,search); # read the previous [current-i] line and split
#print array1[9];
sub(":","",array1[9]); # seperate the database name
tmp=array1[9]; # assigne database name found on line to tmp
#print tmp " ####" array1[9] " ### : " i "#### " array2[12];
i++; # increment the counter
}
if_failed=index(array1[12],"%");
if(array1[12]=="(100%)")
{ dumptype="database"; } # Check if it is database dump
else if(if_failed!=0){dumptype="unable to decide"} # This might occure if log file is inconsistant
else{dumptype="X'action";} # Check if it is transaction dump
printf("%4s %s %2s %s %s %15s %30s %s\n",backupno,array2[1],array2[2],array2[4],array2[3],array1[10],array2[12],dumptype);
tmp="NA";
prevback=substr($0,1,6);
backupno=backupno+1;}
{ a[NR] = $0 } # re-initialise array
#
# end
#

Log File Listing:

 
May 16 13:29:05 2012: Backup Server: 2.23.1.1: Connection from Server ACSTEST on Host AUS5LW00929542 with HostProcid .
May 16 13:29:50 2012: Backup Server: 2.23.1.1: Connection from Server ACSTEST on Host AUS5LW00929542 with HostProcid .
May 16 13:29:50 2012: Backup Server: 4.172.1.1: The value of 'reserved pages threshold' has been set to 85%.
May 16 13:29:50 2012: Backup Server: 4.172.1.2: The value of 'allocated pages threshold' has been set to 40%.
May 16 13:29:50 2012: Backup Server: 2.23.1.1: Connection from Server ACSTEST on Host AUS5LW00929542 with HostProcid .
May 16 13:29:50 2012: Backup Server: 2.23.1.1: Connection from Server ACSTEST on Host AUS5LW00929542 with HostProcid .
May 16 13:29:50 2012: Backup Server: 4.41.1.1: Creating new disk file c:\dbdumps\acstest.dmp.
May 16 13:29:51 2012: Backup Server: 1.70.1.2: Configuring the shared memory per stripe to 786432 bytes.
May 16 13:29:51 2012: Backup Server: 6.28.1.1: Dumpfile name 'TestDB121370BDCE ' section number 1 mounted on disk file 'c:\dbdumps\acstest.dmp'
May 16 13:29:51 2012: D00: Attempting Non Buffered I/O for device 'C:\Windows\system32\TestDB.dat'
May 16 13:29:51 2012: D00: Attempting Non Buffered I/O for device 'C:\Windows\system32\TestDB.log'
May 16 13:29:52 2012: Backup Server: 4.188.1.1: Database TestDB: 1412 kilobytes (1%) DUMPED.
May 16 13:29:52 2012: Backup Server: 4.188.1.1: Database TestDB: 2198 kilobytes (11%) DUMPED.
May 16 13:29:53 2012: Backup Server: 4.188.1.1: Database TestDB: 2872 kilobytes (24%) DUMPED.
May 16 13:29:55 2012: Backup Server: 4.188.1.1: Database TestDB: 3546 kilobytes (37%) DUMPED.
May 16 13:29:55 2012: Backup Server: 4.188.1.1: Database TestDB: 4220 kilobytes (50%) DUMPED.
May 16 13:29:56 2012: Backup Server: 4.188.1.1: Database TestDB: 4894 kilobytes (63%) DUMPED.
May 16 13:29:56 2012: Backup Server: 4.188.1.1: Database TestDB: 5568 kilobytes (76%) DUMPED.
May 16 13:29:57 2012: Backup Server: 4.188.1.1: Database TestDB: 6242 kilobytes (89%) DUMPED.
May 16 13:29:58 2012: Backup Server: 4.188.1.1: Database TestDB: 6860 kilobytes (100%) DUMPED.
May 16 13:30:00 2012: Backup Server: 3.43.1.1: Dump phase number 1 completed.
May 16 13:30:00 2012: Backup Server: 3.43.1.1: Dump phase number 2 completed.
May 16 13:30:00 2012: Backup Server: 3.43.1.1: Dump phase number 3 completed.
May 16 13:30:00 2012: Backup Server: 4.188.1.1: Database TestDB: 6874 kilobytes (100%) DUMPED.
May 16 13:30:00 2012: Backup Server: 3.42.1.1: DUMP is complete (database TestDB).
May 16 13:30:09 2012: Backup Server: 2.23.1.1: Connection from Server ACSTEST on Host AUS5LW00929542 with HostProcid .
May 16 13:30:41 2012: Backup Server: 2.23.1.1: Connection from Server ACSTEST on Host AUS5LW00929542 with HostProcid .
May 16 13:30:41 2012: Backup Server: 4.172.1.1: The value of 'reserved pages threshold' has been set to 85%.
May 16 13:30:41 2012: Backup Server: 4.172.1.2: The value of 'allocated pages threshold' has been set to 40%.
May 16 13:30:41 2012: Backup Server: 2.23.1.1: Connection from Server ACSTEST on Host AUS5LW00929542 with HostProcid .
May 16 13:30:41 2012: Backup Server: 2.23.1.1: Connection from Server ACSTEST on Host AUS5LW00929542 with HostProcid .
May 16 13:30:41 2012: Backup Server: 1.70.1.2: Configuring the shared memory per stripe to 786432 bytes.
May 16 13:30:41 2012: Backup Server: 6.28.1.1: Dumpfile name 'master121370BE01 ' section number 1 mounted on disk file 'c:\dbdumps\master.dmp'
May 16 13:30:41 2012: D00: Attempting Non Buffered I/O for device 'C:\Sybase\data\master.dat'
May 16 13:30:42 2012: Backup Server: 4.188.1.1: Database master: 1916 kilobytes (11%) DUMPED.
May 16 13:30:42 2012: Backup Server: 4.188.1.1: Database master: 10846 kilobytes (35%) DUMPED.
May 16 13:30:42 2012: Backup Server: 4.188.1.1: Database master: 11448 kilobytes (100%) DUMPED.
May 16 13:30:44 2012: Backup Server: 3.43.1.1: Dump phase number 1 completed.
May 16 13:30:44 2012: Backup Server: 3.43.1.1: Dump phase number 2 completed.
May 16 13:30:44 2012: Backup Server: 3.43.1.1: Dump phase number 3 completed.
May 16 13:30:44 2012: Backup Server: 4.188.1.1: Database master: 11462 kilobytes (100%) DUMPED.
May 16 13:30:44 2012: Backup Server: 3.42.1.1: DUMP is complete (database master).

Please reformat the code above, it's almost unreadable.

Your program works absolutely fine on Linux here:

$ awk -f garble.awk data

SRNO DATE : TIME SIZE IN(KB) DATABASE NAME DUMP TYPE
   1 May 16 2012: 13:30:00            6874                         TestDB database
   2 May 16 2012: 13:30:44           11462                         master database

$

...so I suspect something else is going on.

Could you post your entire KSH script, not just the awk part?

#!/usr/bin/ksh
awk -f backup_check.awk ACSTEST_BS.log > Backup_Check.rpt
exit 0

[/SIZE]

It's unusual for Linux to have awk as anything but gawk, but then, it's unusual for Linux to have ksh, too. So try 'gawk' or 'nawk'.

The shell shouldn't matter. I was able to reproduce the endless loop. You have the log saved in DOS format. You can either use dos2unix, or maybe just modify this:

sub ("\\).","",array2[12]);

Because with DOS line endings your while loop will never succeed since array2[12] would contain, for example, TestDB\r .

edit: This is what I replaced it with sub(/\).\r?/,"",array2[12]); and it ran successfully.

1 Like