Listing 1. Data Collection Script

# Numbered lines represent 1 line regardless of
# wrap. Blank lines have been deleted
 1   #!/bin/bash
 2   # $Header: /var/log/sar/RCS/sa,v 1.2
       1997/06/19 03:59:42 dgavin Exp $
 4   # $Log: sa,v $
 5   # Revision 1.2  1997/06/19 03:59:42  dgavin
 6   # cleanup
 7   # dgavin
 9   # Revision 1.1  1997/06/12 03:34:56  dgavin
10   # Initial revision
12   #
13   cd /var/log/sar/data
14   TIME=`date +"%H%M"`
15   DATE=`date +"%b%d.%y"`
17   # Collect the memory and swap stats
18   awk '
19   /^Mem: / {
20     printf("'${TIME}' %s\n",substr($0,5))
     >>"mem.'${DATE}'";
21   }
22   /^Swap: / {
23     printf("'${TIME}' %s\n",substr($0,6))
     >>"swap.'${DATE}'";
24   }
25   ' /proc/meminfo
27   # collect the active network interface stats.
       If ppp hasn't been used
28   # There won't be any ppp line.
29   awk '
30   /^  eth/ {
31     printf("'${TIME}' %s\n",substr($0,8))
     >>substr($0,3,4)".'${DATE}'";
32   }
33   /^  ppp/ {
34     printf("'${TIME}' %s\n",substr($0,8))
     >7gt;substr($0,3,4)".'${DATE}'";
35   }
36   ' /proc/net/dev
38   # Collect CPU, disk I/O, paging, interrupts,
       context switching, and processes
39   awk '
40   /^cpu/ {
41     printf("'${TIME}' %s\n",substr($0,6))
     >>"cpu.'${DATE}'";
42   }
43   /^disk / {
44     d=split($0,disk);
45   }
46   /^disk_rio / {
47     d=split($0,disk_rio);
48   }
49   /^disk_wio / {
50     d=split($0,disk_wio);
51   }
52   /^disk_rblk / {
53     d=split($0,disk_rblk);
54   }
55   /^disk_wblk / {
56     d=split($0,disk_wblk);
57     printf("'${TIME}'")
     >>"disk.'${DATE}'";
58     for (r = 2; r <= d ; r ++ ) {
59     printf(" %s %s %s %s %s",
60      disk[r],disk_rio[r],disk_wio[r],
61      disk_rblk[r],disk_wblk[r])
     >>"disk.'${DATE}'";}
62     printf("\n")
     >>"disk.'${DATE}'";
63   }
64   /^page/ {
65     printf("'${TIME}' %s\n",substr($0,6))
     >>"page.'${DATE}'";
66   }
67   /^swap/ {
68     printf("'${TIME}' %s\n",substr($0,6))
     >>"swap.'${DATE}'";
69   }
70   /^intr/ {
71     printf("'${TIME}' %s\n",substr($0,6))
     >>"intr.'${DATE}'";
72   }
73   /^ctxt/ {
74     printf("'${TIME}' %s\n",substr($0,6))
     >>"ctxt.'${DATE}'";
75   }
76   /^processes/ {
77     printf("'${TIME}' %s\n",$2)
     >>"processes.'${DATE}'";
78   }
79   ' /proc/stat