Annotation of 43BSDTahoe/usr.bin/uucp/UUAIDS/sys_awk, revision 1.1.1.1

1.1       root        1: # An awk script for printing a pretty report of UUCP activities from the
                      2: # UUCP SYSLOG - Erik E. Fair   October 2, 1984
                      3: #
                      4: # v7 UUCP
                      5: $4 == "received" {
                      6:        sysname[$2] = $2;
                      7:        by_rec[$2] += $6;
                      8:        sec_rec[$2] += $8;
                      9:        sys_xf[$2] ++;
                     10: }
                     11: #
                     12: # 4.2 BSD UUCP
                     13: $5 == "received" {
                     14:        sysname[$2] = $2;
                     15:        by_rec[$2] += $7;
                     16:        sec_rec[$2] += $9;
                     17:        sys_xf[$2] ++;
                     18: }
                     19: #
                     20: # System V UUCP
                     21: $6 == "<-" {
                     22:        $1 = substr($1, 1, (index($1, "!") - 1));
                     23:        sysname[$1] = $1;
                     24:        by_rec[$1] += $7;
                     25:        sec_rec[$1] += $9;
                     26:        sys_xf[$1] ++;
                     27: }
                     28: #
                     29: # v7 UUCP
                     30: $4 == "sent" {
                     31:        sysname[$2] = $2;
                     32:        by_xmt[$2] += $6;
                     33:        sec_xmt[$2] += $8;
                     34:        sys_xf[$2] ++;
                     35: }
                     36: #
                     37: # 4.2 BSD UUCP
                     38: $5 == "sent" {
                     39:        sysname[$2] = $2;
                     40:        by_xmt[$2] += $7;
                     41:        sec_xmt[$2] += $9;
                     42:        sys_xf[$2] ++;
                     43: }
                     44: #
                     45: # System V UUCP
                     46: $6 == "->" {
                     47:        $1 = substr($1, 1, (index($1, "!") - 1));
                     48:        sysname[$1] = $1;
                     49:        by_xmt[$1] += $7;
                     50:        sec_xmt[$1] += $9;
                     51:        sys_xf[$1] ++;
                     52: }
                     53: END {
                     54: #
                     55: # print a report header
                     56:        printf("System     Xfers  Bytes rec  Bytes xmt   Connect  Avg Xf  Avg rec  Avg xmt\n")
                     57:        for(i in sysname) {
                     58: #
                     59: # sort report by most connect time (selection sort)
                     60:                first = 0;
                     61:                for(j in sysname) {
                     62:                        if (sys_xf[j] > 0) {
                     63:                                tmp1 = sec_xmt[j];
                     64:                                tmp2 = sec_rec[j];
                     65: # Stupid AWK bug - needs a simple expression
                     66:                                time = (tmp1 + tmp2);
                     67:                                if (time > first) {
                     68:                                        first = time;
                     69:                                        sys = sysname[j];
                     70:                                }
                     71:                        }
                     72:                }
                     73: #
                     74: # 4.2 BSD awk seems to have problems. This check should not be necessary.
                     75: # Oddly enough, this problem also shows up in System V. WHY???
                     76:                if (sys_xf[sys] != 0) {
                     77: #
                     78: # time for some bean counting
                     79:                        tmp1       = sec_xmt[sys];
                     80:                        tmp2       = sec_rec[sys];
                     81: # Stupid AWK bug - needs a simple expression
                     82:                        time       = (tmp1 + tmp2);
                     83:                        hours      = time / 3600;
                     84:                        sec        = time % 3600;
                     85:                        min        = sec / 60;
                     86:                        sec        %= 60;
                     87:                        tot_xf     += sys_xf[sys];
                     88:                        tot_by_rec += by_rec[sys];
                     89:                        tot_by_xmt += by_xmt[sys];
                     90:                        tot_time   += time;
                     91: #
                     92: # protect myself against mathematical crime (divide by zero)
                     93:                        if (sec_rec[sys] == 0)
                     94:                                sec_rec[sys] = 1;
                     95:                        if (sec_xmt[sys] == 0)
                     96:                                sec_xmt[sys] = 1;
                     97: #
                     98: # print a pretty system report (god what an awful printf format...)
                     99:                        printf("%-8s%8d%11d%11d%4d:%.2d:%.2d%8d%9d%9d\n", \
                    100: sysname[sys], sys_xf[sys], by_rec[sys], by_xmt[sys], hours, min, sec, \
                    101: ((by_rec[sys] + by_xmt[sys]) / sys_xf[sys]), \
                    102: (by_rec[sys]  / sec_rec[sys]), \
                    103: (by_xmt[sys]  / sec_xmt[sys]));
                    104: #
                    105: # make certain we will not see this system again... (selection sort)
                    106:                        sys_xf[sys] = 0;
                    107:                }
                    108:        }
                    109: #
                    110: # calculate time split for total time (and print totals [*shudder*])
                    111:        hours = tot_time / 3600;
                    112:        sec = tot_time % 3600;
                    113:        min = sec / 60;
                    114:        sec %= 60;
                    115:        printf("\n%-8s%8d%11d%11d%4d:%.2d:%.2d\n", \
                    116:        "TOTALS", tot_xf, tot_by_rec, tot_by_xmt, hours, min, sec);
                    117: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.