AWK Program Not Executing On Linux with KSH


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK Program Not Executing On Linux with KSH
# 1  
Old 05-17-2012
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
Code:
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:
Code:
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:
Code:
echo $0
-ksh


Program Listing:
Code:
#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:
Code:
 
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).

Moderator's Comments:
Mod Comment How to use code tags when posting data and code samples.

Last edited by Franklin52; 05-17-2012 at 02:24 PM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 05-17-2012
Please reformat the code above, it's almost unreadable.
# 3  
Old 05-17-2012
Your program works absolutely fine on Linux here:

Code:
$ 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?
# 4  
Old 05-17-2012
AWK Program Not Executing on Linux with KSH

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


# 5  
Old 05-17-2012
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'.
# 6  
Old 05-17-2012
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:

Code:
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.
This User Gave Thanks to neutronscott For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Error in executing the C program

Hello Friends, I have written a code for the unisex bathroom which makes a policy that when a woman is in the bathroom only other women may enter, but not men, and vice versa. This program consists of four functions which a user defines but these functions are not properly working while... (4 Replies)
Discussion started by: Ravi Tej
4 Replies

2. UNIX for Dummies Questions & Answers

executing a different program

What system calls or commands do I need to use in order to execute a different program from an already running process? (1 Reply)
Discussion started by: justOne21
1 Replies

3. UNIX for Dummies Questions & Answers

Difference Between executing llike ./myscript.ksh and . ./myscript.ksh

Hi , What is the diffence between executing the script like ./myscript.ksh . ./myscript.ksh I have found 2 difference but could not find the reason 1. If i export a variable in myscript.ksh and execute it like . ./myscript.ksh the i can access the other scripts that are present in... (5 Replies)
Discussion started by: max_hammer
5 Replies

4. Shell Programming and Scripting

Executing WIN32OLE program

Hello, Please help me out to execute this perl program: #!/usr/bin/perl -w use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn = 3; # die on errors... # get already active Excel application or open new my... (6 Replies)
Discussion started by: suvenduperl
6 Replies

5. Shell Programming and Scripting

Executing a Java Program

I am entirely new to shell scripting and would like to create a script to execute a java program called Main. I've already compiled it and placed the .java and .class files at /root/javaTest. Next I made a shell script that simply contained: java /root/javaTest/Main . I made the script... (2 Replies)
Discussion started by: hypnotic_meat
2 Replies

6. Solaris

How to know the size of the program currently executing in memory

hey everybody, i am currently working on solaris 10 os on a m5000 server. my problem is when i want the exact size of a program in execution, i am unable to do it. earlier i thought the RSS field of prstat but because of its large size it cant be the size. pmap -x shows some output but it includes... (2 Replies)
Discussion started by: aryansheikh
2 Replies

7. Programming

Trubble in executing the cpp program...

I wrote a code like this....... #include <iostream> #include <stdio.h> #include <mysql.h> #include <string.h> #include <stdlib.h> using namespace std; #include "Connection.h" int main() { char *Host = (char *)"localhost"; char *Database =(char *)"sachin"; char... (3 Replies)
Discussion started by: ps_sach
3 Replies

8. Programming

after executing execvp()... program hangs up

Hi , I m actually trying to implement pipes program,but after executing the execvp(),my program is getting hanged up :mad: Actaully i m getting the desired output expected from execvp()...but once results are displayed on the output screen ,program is getting hanged up values of... (3 Replies)
Discussion started by: Crab
3 Replies

9. Programming

Executing an .ec program in different informix versions

Hi all, I tried writing an .ec program connecting to informix database from solaris platform Sun 5.7 informix version that i had to used when i compiled the program was 9.21.UC3 the binary when i ported solaris box with informix version 9.40.UC5 i am unable to run that i am encountering... (0 Replies)
Discussion started by: matrixmadhan
0 Replies

10. Programming

executing a program within a program

Read the title: how do i do it? (4 Replies)
Discussion started by: Gekko
4 Replies
Login or Register to Ask a Question