Cover V01, I03
Article
Figure 1
Figure 2
Figure 3
Figure 4
Listing 1
Listing 2
Listing 3

sep92.tar


Listing 3: The sysload.sh Script

1: #
2: # sysload.sh: log system load
3: #             (called from cron table)
4: #
5: # Written by Leor Zolman, 6/17/91
6: #
7: # usage:
8: #   sysload.sh daily    (run periodically throughout the day)
9: #   sysload.sh final    (run once at the end of the day)
10: #
11: # When $1 is "daily": adds a line to DAYLOG with the current 15-minute
12: #   load average.
13: #
14: # When $1 is "final": computes average of all daily entries in DAYLOG. An
15: #   entry noting this average is appended to AVGLOG. The contents of DAYLOG
16: #   and the average are then appended  to LOADLOG,  and DAYLOG is deleted.
17: #   Then, if this is Friday, the average of the 5 daily averages is
18: #   also computed and appended to AVGLOG.
19: #
20: #
21:
22: debug=N
23: ADMINGRP=tech           # System administration group id on your system
24:
25: if [ $debug = N ]; then
26:     DAYLOG=/u3/General/Ltmp/sysload.day
27:     LOADLOG=/u3/General/Ltmp/sysload.log
28:     AVGLOG=/u3/General/Ltmp/sysload.avg
29: else
30:     DAYLOG=day
31:     LOADLOG=log
32:     AVGLOG=avg
33: fi
34:
35: [ $# -ne 1 ] && echo "usage: $0 {daily | final}" >&2 && exit 1
36:
37: case $1 in
38:     daily)
39:         if [ ! -r $DAYLOG ]; then
40:             touch $DAYLOG
41:             chmod 664 $DAYLOG
42:             chgrp $ADMINGRP $DAYLOG
43:         fi
44:         echo `date +"%a %D %T"`: `uptime |
45:         awk '{
46:             txt = $(NR)
47:             if (substr(txt, length(txt), length(txt)) == ",")
48:                 txt = substr(txt, 1, length(txt)-1)
49:             print txt
50:         }'` >>$DAYLOG
51:         break;;
52:
53:     final)
54:         [ ! -r $DAYLOG ] && echo "$0: Cannot open $DAYLOG" >&2
&& exit 1
55:         if [ ! -r $LOADLOG ]; then
56:             touch $LOADLOG
57:             chmod 664 $LOADLOG
58:             chgrp $ADMINGRP $LOADLOG
59:         fi
60:         if [ ! -r $AVGLOG ]; then
61:             touch $AVGLOG
62:             chmod 664 $AVGLOG
63:             chgrp $ADMINGRP $AVGLOG
64:         fi
65:         tmp=`tmpname sld`
66:         echo "`date +\"%a %D\"`: \c" >$tmp
67:         awk '{
68:             total = total + $4
69:             count = count + 1
70:             }
71:             END {
72:                 printf("\tAverage for the day: %5.2f\n", total / count)
73:             }' <$DAYLOG >>$tmp
74:
75:         cat $DAYLOG >>$LOADLOG      # update full log
76:         cat $tmp >>$LOADLOG
77:         echo >>$LOADLOG
78:
79:         cat $tmp >>$AVGLOG          # update average only log
80:         if [ `date +%w` = 5 ]; then # if friday, then
81:             tail -5 $AVGLOG |
82:                 awk '{
83:                     total = total + $7 }
84:                     END { printf "\t\tAVERAGE FOR THE WEEK: %5.2f\n",
85:                             total / 5
86:                     }' >> $AVGLOG   # append weekly average
87:             echo >>$AVGLOG          # blank line between weeks
88:         fi
89:
90:         rm $DAYLOG $tmp             # remove daily temp file
91:         ;;
92:
93:     *) echo "usage: $0 {daily | final}" >&2  && exit 1;;
94: esac