Hello all,
I've got what I'm pretty sure is a simple problem, but I just can't seem to work past it. I'm trying to use awk to pretty up a log file, and calculate a percentage.
The log file looks like this:
[root@mys-nycnm-srv01 rtaStats]# tail strtovrUsage
20090531-18:15:45 RSreq - 24, RSsuc - 24, RSrun - 78, RSerr - 0,
20090531-18:25:45 RSreq - 17, RSsuc - 17, RSrun - 72, RSerr - 0,
20090531-18:35:45 RSreq - 19, RSsuc - 19, RSrun - 72, RSerr - 0,
20090531-18:45:45 RSreq - 16, RSsuc - 16, RSrun - 60, RSerr - 0,
20090531-18:55:45 RSreq - 14, RSsuc - 14, RSrun - 62, RSerr - 0,
20090531-19:05:46 RSreq - 27, RSsuc - 26, RSrun - 61, RSerr - 1,
20090531-19:15:46 RSreq - 37, RSsuc - 37, RSrun - 74, RSerr - 0,
20090531-19:25:46 RSreq - 48, RSsuc - 46, RSrun - 84, RSerr - 2,
20090531-19:35:46 RSreq - 54, RSsuc - 54, RSrun - 106, RSerr - 0,
20090531-19:36:52 RSreq - 0, RSsuc - 0, RSrun - 107, RSerr - 0,
If I fun something simple like:
[root@mys-nycnm-srv01 ~]# cat `which SOperf`
tail -f /usr/local/mystro/scripts/twctools/rtaStats/strtovrUsage|awk '{print "Requests = " $4 "Success = " $7 "Running Streams = " $10 "Errors = " $13 "Percentage = " ($7 / $4 )*100 }'
[root@mys-nycnm-srv01 ~]# SOperf
Requests = 47,Success = 47,Running Streams = 122,Errors = 0,Percentage = 100
Requests = 62,Success = 60,Running Streams = 122,Errors = 2,Percentage = 96.7742
Requests = 56,Success = 56,Running Streams = 132,Errors = 0,Percentage = 100
Requests = 50,Success = 50,Running Streams = 124,Errors = 0,Percentage = 100
Requests = 65,Success = 63,Running Streams = 138,Errors = 0,Percentage = 96.9231
It works, but it's a little simpler than what I'd like. I tried doing the following:
#!/bin/bash
printf "Time\t\t\tRequests\tSuccess\tRunning\tError\tPercentage\n"
tail /usr/local/mystro/scripts/twctools/rtaStats/strtovrUsage |\
awk \
'***** = $1} \
{req = $4} \
{suc = $7} \
{err = $13}\
{run = $10}\
END \
{print tim "\t" req "\t\t" suc "\t" run "\t" err "\t" (suc / req)*100 }'
Time Requests Success Running Error Percentage
20090531-21:35:47 65, 64, 146, 1, 98.4615
But I only get the one line of results, and it won't work with a tail -f.
If it matters, here is the information for the system I'm working on.
Linux mys-nycnm-srv01 2.6.9-34.ELsmp #1 SMP Fri Feb 24 16:54:53 EST 2006 i686 i686 i386 GNU/Linux
/usr/bin/awk: symbolic link to `../../bin/gawk'
Also, is there an effective way to work in "divide by 0" error protection into what I'm trying to do (bearing in mind my obviously low skill level?)