vk239
vk239

Reputation: 1044

AWK Unexpected token error

I came up with the below script to list out calls which take longer than 10000000 microseconds (ServiceDuration in our logs has value logged in microseconds) from the server log file which stores all calls coming to the service.

servicedurationlimit.awk

#!/bin/sh
dir1=$1/*.log

# for each log file in the input dir
for file1 in $dir1
do
        echo $file1":"
        awk  '/#BeginLogEntry|ServiceDuration/ {
                #get slow running service's information
                if ($1 == "#BeginLogEntry")
                {
                        split($0, a, "\t");
                        servinfo=a[3]" ServiceAt:"a[2];
                } else {
                        getline;
                        if ($0 > 10000000)
                        {
                                print servinfo", ServDur:"$0
                        }
                }
        }' $file1
done

On running the script I get below error:

./servicedurationlimit.awk /path/to/server/logs/
./servicedurationlimit.awk: line 12: syntax error near unexpected token `$0,'
./servicedurationlimit.awk: line 12: `                  split($0, a, "\t"); '

Can you please help me understand what could be causing this?

Below is the sample log file (which has 2 log entries):

#BeginLogEntry  04.13 20:11:11.671  BROWSE_ALL
@Properties LocalData
IsJson=1
UserTimeZone=utc
@end
@IdcRSet AuditProps
2
auditPropertyKey
auditPropertyValue
ServiceDuration
62818
ServiceStartTime
{ts '2015-04-13 20:11:11.671'}
@end
#EndLogEntry    04.13 20:11:11.671  BROWSE_ALL
#BeginLogEntry  04.13 21:12:11.671  BROWSE_SOME
@Properties LocalData
IsJson=1
UserTimeZone=utc
@end
@IdcRSet AuditProps
2
auditPropertyKey
auditPropertyValue
ServiceDuration
162818123
ServiceStartTime
{ts '2015-04-13 21:12:11.671'}
@end
#EndLogEntry    04.13 21:12:11.671  BROWSE_SOME

Below is the output I am expecting after running the script on log file containing above log entries.

BROWSE_SOME ServiceAt:04.13 21:12:11.671, ServDur: 162818123

awk Version information

$ awk --version
GNU Awk 3.1.5

Upvotes: 0

Views: 2644

Answers (1)

jkdba
jkdba

Reputation: 2509

I am running GNU Awk 4.0.2 and your code gives this error on my box:

awk: cmd. line:2:       #get slow running services
awk: cmd. line:2:       ^ syntax error
./test.sh: line 11: syntax error near unexpected token `$0,'
./test.sh: line 11: `        split($0, a, "\t");'

However I believe you just need to remove the ' single quote from your comment:

#get slow running service's

Upvotes: 5

Related Questions