The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
calculating sum of fields in a file dsravan Shell Programming and Scripting 4 01-03-2008 01:00 PM
Calculating quantiles in SQL figaro UNIX for Dummies Questions & Answers 3 11-20-2007 05:55 PM
compare files and calculating tonet Shell Programming and Scripting 6 01-26-2007 06:13 AM
calculating size of int apoorvasharma80 High Level Programming 10 11-01-2006 06:44 PM
Calculating the day of the week ligs UNIX for Dummies Questions & Answers 4 10-27-2001 10:28 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 01-25-2007
kekanap's Avatar
kekanap kekanap is offline
Registered User
  
 

Join Date: Sep 2003
Location: South Africa
Posts: 36
Calculating the average

This is the cronjob
----------------------

root@a7germ:/home/paxtemp [277] > crontab -l|grep test
57 * * * * /home/paxtemp/test_1.sh
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /home/paxtemp/test.sh
root@a7germ:/home/paxtemp [278] >


This is the contents of test.sh script
---------------------------------------

root@a7germ:/home/paxtemp [279] > cat test.sh
#!/usr/bin/ksh
#
#Author: Paxley Kekana 01-Nov-2006
#
#set -x
#
export NOW=`date +"%Y%m%d"`
export NOK=`date +"%Y%m%d-%T"`
export NOF=`date +"%H"`
#
echo $NOW
#
cd /var/opt/SURGE/logs
ll -ltr som*|tail -1 > /tmp/pax/a.txt
awk '{print $9}' /tmp/pax/a.txt > /tmp/pax/b.txt
#
dd=$(</tmp/pax/b.txt)
#
grep "Interval No. SURs/Sec =" $dd | tail -1 > /tmp/pax/c.txt
awk '{print ($10*2)}' /tmp/pax/c.txt > /tmp/pax/d.txt
#awk '{print $10}' /tmp/pax/c.txt > /tmp/pax/d.txt
#
ee=$(</tmp/pax/d.txt)
#
#=======================================================#
#
cd ../../DataBroker/logs
ll -ltr sdb.log*|tail -1 > /tmp/pax/a1.txt
awk '{print $9}' /tmp/pax/a1.txt > /tmp/pax/b1.txt
#
ss=$(</tmp/pax/b1.txt)
#
grep sdbApp.cpp $ss | tail -2 |head -1> /tmp/pax/c1.txt #Edited on 14-Nov-2006
#grep "Output Rate :" $ss | tail -1 > /tmp/pax/c1.txt #Commented out on 14-Nov-2006
awk '{print $9}' /tmp/pax/c1.txt > /tmp/pax/d1.txt
#awk '{print ((NF > 9) ? $10 : $9) }' /tmp/pax/c1.txt > /tmp/pax/d1.txt #Commented out 14-Nov-2006
#
ff=$(</tmp/pax/d1.txt)
#
#=========================================================#
#
ll -ltr sdb_*.log* |tail -1 > /tmp/pax/a2.txt
awk '{print $9}' /tmp/pax/a2.txt > /tmp/pax/b2.txt
#
gg=$(</tmp/pax/b2.txt)
#
grep "Output Rate" $gg |tail -1 > /tmp/pax/c2.txt
awk '{print $9}' /tmp/pax/c2.txt > /tmp/pax/d2.txt
#
aa=$(</tmp/pax/d2.txt)
#
#============================================================#
echo
echo
#
#((zz=$ee+$ff+$aa))
#
#echo $zz
echo "scale=1; $aa+$ee+$ff"|bc > /tmp/pax/c3.txt
echo #?
#
zz=$(</tmp/pax/c3.txt)
echo $NOK $zz >> /tmp/pax/results/$NOW.txt
#echo $zz >> /tmp/pax/$NOW.txt
echo $zz >> /tmp/pax/results/$NOF.txt
root@a7germ:/home/paxtemp [280] >

This is the contents of the test_1.sh script
--------------------------------------------

root@a7germ:/home/paxtemp [281] > cat test_1.sh
#!/usr/bin/ksh
#
#Author: Paxley Kekana 20-Nov-2006
#
#set -x
#
export NOW=`date +"%Y%m%d"`
export NOF=`date +"%H"`

#
echo "=======================================" >> /tmp/pax/results/$NOW.txt
#
cd /tmp/pax/results

awk '{s+=$1}END {printf("sum = %f Average = %f\n",s,s/NR)}' $NOF.txt >> /tmp/pax/results/$NOW.txt
echo
#
echo "=======================================" >> /tmp/pax/results/$NOW.txt
#
root@a7germ:/home/paxtemp [282] >

This is the output from one of the output files
-------------------------------------------------

20070123-07:05:01 448.786
20070123-07:10:01 450.359
20070123-07:15:00 450.706
20070123-07:20:00 451.693
20070123-07:25:00 452.346
20070123-07:30:00 452.079
20070123-07:35:00 446.933
20070123-07:40:00 447.399
20070123-07:45:00 447.226
20070123-07:50:00 445.639
20070123-07:55:00 438.506
=======================================
sum = 348791.968000 Average = 454.156208
=======================================
20070123-08:00:01 437.319
20070123-08:05:00 488.893
20070123-08:10:00 486.279
20070123-08:15:00 482.586
20070123-08:20:00 484.853
20070123-08:25:00 483.106
20070123-08:30:00 478.853
20070123-08:35:00 480.053
20070123-08:40:00 481.199
20070123-08:45:00 480.959
20070123-08:50:00 480.413
20070123-08:55:00 483.173
=======================================
sum = 458765.924000 Average = 597.351464
=======================================
20070123-09:00:00 483.746
20070123-09:05:00 642.313
20070123-09:10:00 635.859
20070123-09:15:00 634.059
20070123-09:20:00 633.353
20070123-09:25:01 635.913
20070123-09:30:00 640.899
20070123-09:35:00 639.046
20070123-09:40:01 636.819
20070123-09:45:01 640.686
20070123-09:50:00 639.219
20070123-09:55:00 syntax error on line 1,
=======================================
sum = 550224.286000 Average = 716.437872
=======================================
20070123-10:00:00 syntax error on line 1,
20070123-10:05:01 734.993
20070123-10:10:00 732.713
20070123-10:15:00 731.739
20070123-10:20:00 731.473
20070123-10:25:00 736.793
20070123-10:30:00 739.099
20070123-10:35:00 735.153
20070123-10:40:00 735.486
20070123-10:45:00 736.033
20070123-10:50:00 734.873
20070123-10:55:00 736.899
=======================================
sum = 594294.818000 Average = 773.821378
=======================================
20070123-11:00:00 734.313
20070123-11:05:00 744.179
20070123-11:10:00 743.019
20070123-11:15:00 745.329
20070123-11:20:00 742.389
20070123-11:25:00 741.739
20070123-11:30:00 739.006
20070123-11:35:00 740.339
20070123-11:40:00 741.699
20070123-11:45:01 742.459
20070123-11:50:00 740.726
20070123-11:55:00 739.553
=======================================
sum = 619803.078000 Average = 807.035258
=======================================
20070123-12:00:00 742.673
20070123-12:05:00 756.779
20070123-12:10:00 757.526
20070123-12:15:00 754.753
20070123-12:20:00 755.073
20070123-12:25:00 754.326
20070123-12:30:00 757.886
20070123-12:35:00 760.739
20070123-12:40:00 758.033
20070123-12:45:00 757.593
20070123-12:50:00 756.913
20070123-12:55:00 757.246
=======================================
sum = 621107.320000 Average = 808.733490
=======================================
20070123-13:00:00 755.033
20070123-13:05:00 739.179
20070123-13:10:00 735.699
20070123-13:15:00 738.779
20070123-13:20:00 734.513
20070123-13:25:01 734.899
20070123-13:30:01 735.766
20070123-13:35:00 737.979
20070123-13:40:00 736.606
20070123-13:45:00 733.366
20070123-13:50:00 738.966
20070123-13:55:00 738.406
=======================================
sum = 615483.403000 Average = 801.410681
=======================================
20070123-14:00:00 738.086
20070123-14:05:01 760.233
20070123-14:10:01 766.073
20070123-14:15:01 763.699
20070123-14:20:00 764.513
20070123-14:25:00 762.806
20070123-14:30:00 762.273
20070123-14:35:00 763.019
20070123-14:40:00 766.139
20070123-14:45:00 764.966
20070123-14:50:00 763.939
20070123-14:55:00 765.766
=======================================
sum = 615336.803000 Average = 801.219796
=======================================
20070123-15:00:00 766.233
20070123-15:05:00 762.853
20070123-15:10:00 763.706
20070123-15:15:00 764.239
20070123-15:20:00 760.946
20070123-15:25:00 764.346
20070123-15:30:00 762.973
20070123-15:35:00 764.119
20070123-15:40:00 764.626
20070123-15:45:00 767.946
20070123-15:50:00 762.573
20070123-15:55:01 768.239
=======================================
sum = 628564.810000 Average = 818.443763
=======================================
20070123-16:00:00 770.666
20070123-16:05:01 683.279
20070123-16:10:01 688.453
20070123-16:15:00 686.866
20070123-16:20:01 687.546
20070123-16:25:00 688.973
20070123-16:30:01 695.079
20070123-16:35:00 694.239
20070123-16:40:00 696.333
20070123-16:45:00 699.919
20070123-16:50:00 694.573
20070123-16:55:00 696.319
=======================================
sum = 626349.391000 Average = 815.559103
=======================================
20070123-17:00:00 697.413
20070123-17:05:01 600.046
20070123-17:10:01 601.966
20070123-17:15:00 595.059
20070123-17:20:00 599.099
20070123-17:25:00 594.619
20070123-17:30:00 597.499
20070123-17:35:00 596.273
20070123-17:40:00 595.366
20070123-17:45:00 597.406
20070123-17:50:00 594.233
20070123-17:55:00 592.006
=======================================
sum = 646678.355000 Average = 832.275875
=======================================
20070123-18:00:00 589.326
20070123-18:05:01 633.206
20070123-18:10:01 631.193
20070123-18:15:01 626.113
20070123-18:20:00 625.513
20070123-18:25:00 622.473
20070123-18:30:00 636.646
20070123-18:35:00 628.233
20070123-18:40:01 623.699
20070123-18:45:01 626.499
20070123-18:50:01 618.353
20070123-18:55:00 621.179
=======================================
sum = 655142.155000 Average = 839.925840
=======================================
20070123-19:00:00 615.406
20070123-19:05:00 722.759
20070123-19:10:00 721.986
20070123-19:15:00 718.919
20070123-19:20:01 719.853
20070123-19:25:01 723.426
20070123-19:30:01 724.173
20070123-19:35:00 721.546
20070123-19:40:00 721.706
20070123-19:45:00 716.866
20070123-19:50:00 718.719
20070123-19:55:00 718.199
=======================================
sum = 670887.911000 Average = 860.112706
=======================================
20070123-20:00:00 720.093
20070123-20:05:00 852.459
20070123-20:10:00 843.939
20070123-20:15:00 848.619
20070123-20:20:01 846.459
20070123-20:25:01 842.619
20070123-20:30:01 847.139
20070123-20:35:00 859.486
20070123-20:40:00 853.459
20070123-20:45:00 848.473
20070123-20:50:01 850.593
20070123-20:55:00 851.966
=======================================
sum = 675971.583000 Average = 866.630235
=======================================
20070123-21:00:00 848.793
20070123-21:05:00 863.973
20070123-21:10:00 861.919
20070123-21:15:00 858.599
20070123-21:20:00 847.813
20070123-21:25:00 849.853
20070123-21:30:00 851.226
20070123-21:35:00 847.733
20070123-21:40:00 846.479
20070123-21:45:01 841.399
20070123-21:50:00 840.173
20070123-21:55:00 832.866
=======================================
sum = 637222.257000 Average = 816.951612
=======================================
20070123-22:00:00 830.093
20070123-22:05:01 730.919
20070123-22:10:00 728.106
20070123-22:15:00 724.706
20070123-22:20:00 730.959
20070123-22:25:00 718.933
20070123-22:30:00 713.213
20070123-22:35:00 709.279
20070123-22:40:01 705.746
20070123-22:45:00 697.946
20070123-22:50:01 698.026
20070123-22:55:00 691.066
=======================================
sum = 560332.761000 Average = 718.375335
=======================================
20070123-23:00:00 693.253
20070123-23:05:00 713.526
20070123-23:10:00 709.473
20070123-23:15:00 707.793
20070123-23:20:00 706.459
20070123-23:25:01 701.526
20070123-23:30:00 700.499
20070123-23:35:00 697.903
20070123-23:40:00 697.286
20070123-23:45:00 693.329
20070123-23:50:01 693.933
20070123-23:55:00 691.633
=======================================
sum = 516424.839000 Average = 662.083127
=======================================
root@a7germ:/tmp/pax/results [287] >



====================================================================================
=THE AVERAGE IS NOT RIGHT. PLEASE GIVE YOUR COMMENTS.===============================
====================================================================================
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:20 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0