Application script named external_Pgm.ksh produces output as below when executed
Current Timestamp = 2009-08-30-23.10.35.603275
No of orders = 10
Cost of new order = USD 10.00
If the same script is execute after 5 mins it produces result as below (Essentially it show the current timestamp, total no of orders placed and total cost of all the orders
Execution after 5mins
Current Timestamp = 2009-08-30-23.15.35.603275
No of orders = 14
Cost of new order = USD 10.00
But I want to produce a report as below
Current Time Total no of Orders No of orders in last 5 mins (calculated by subtracting current order count and order placed 5 minutes back
13:10 10 10
13:15 14 4
13:20 19 5
===
loop_count=0
while [ "$loop_count" -lt 10 ]
do
external_Pgm.ksh > external_Pgm.ksh.out
cat external_Pgm.ksh.out | nawk '{
if (index($0, "Current Timestamp") > 0) v_time = $4
if (index($0, "No of orders") > 0) no_orders = $5
} END {
printf ("%5d %5d %5d\n",
v_time,
no_orders)
;
}' >> my_script.out
loop_count=`expr $loop_count + 1`
sleep 600
done
However I'm facing problem in determing the no of orders placed in the last 5 minutes since the variable no_orders cannot be retained outside the nawk loop. Please advice how to handle this requirement within this script.
Current Timestamp = 2009-08-30-23.10.35.603275
No of orders = 10
Cost of new order = USD 10.00
If the same script is execute after 5 mins it produces result as below (Essentially it show the current timestamp, total no of orders placed and total cost of all the orders
Execution after 5mins
Current Timestamp = 2009-08-30-23.15.35.603275
No of orders = 14
Cost of new order = USD 10.00
But I want to produce a report as below
Current Time Total no of Orders No of orders in last 5 mins (calculated by subtracting current order count and order placed 5 minutes back
13:10 10 10
13:15 14 4
13:20 19 5
===
loop_count=0
while [ "$loop_count" -lt 10 ]
do
external_Pgm.ksh > external_Pgm.ksh.out
cat external_Pgm.ksh.out | nawk '{
if (index($0, "Current Timestamp") > 0) v_time = $4
if (index($0, "No of orders") > 0) no_orders = $5
} END {
printf ("%5d %5d %5d\n",
v_time,
no_orders)
;
}' >> my_script.out
loop_count=`expr $loop_count + 1`
sleep 600
done
However I'm facing problem in determing the no of orders placed in the last 5 minutes since the variable no_orders cannot be retained outside the nawk loop. Please advice how to handle this requirement within this script.