Im trying to write something in bash to show the data logged by sar for the month. What I have so far is
for file in /var/log/sa/sa??; do sar -q -f "$file" | grep "^.\{35\}1[1-9][0-9]"; done
This shows the data that I want in that it shows any time the load was over 110, the problem is that it just shows the hours that this happened, not the day. Here is some example output:
# for file in /var/log/sa/sa??; do sar -q -f "$file" | grep "^.\{35\}1[1-9][0-9]"; done
02:57:01 AM 72 1318 142.61 54.60 29.89
02:58:19 AM 137 1366 135.52 71.45 37.77
01:20:10 AM 205 1246 112.29 55.22 38.40
01:22:02 AM 109 1260 195.54 102.06 57.06
01:23:01 AM 63 1219 128.44 100.63 59.44
01:26:02 AM 113 1380 120.67 99.85 65.70
01:27:02 AM 133 1371 133.72 107.76 70.58
01:28:12 AM 178 1280 120.40 108.98 73.71
03:50:02 AM 121 1443 189.25 168.81 82.88
05:56:17 AM 208 1231 113.36 41.01 20.65
05:57:06 AM 145 1227 128.45 56.78 27.11
05:58:06 AM 160 1265 149.87 74.99 35.18
05:59:01 AM 136 1370 179.49 95.48 44.45
06:00:01 AM 93 1404 156.11 105.23 51.06
06:01:01 AM 34 1310 119.41 105.12 54.48
10:07:04 AM 169 1524 110.05 82.17 55.00
10:08:01 AM 105 1466 122.00 91.18 59.82
02:26:10 AM 181 1276 149.12 62.34 34.25
02:27:05 AM 137 1327 169.27 81.70 42.43
12:02:01 AM 49 1326 110.65 57.31 39.68
07:29:02 PM 136 1279 116.35 47.18 23.75
07:30:01 PM 124 1378 116.51 58.86 29.10
07:31:03 PM 93 1200 123.80 71.66 35.50
07:32:01 PM 113 1324 138.65 84.84 42.10
07:33:01 PM 76 1411 119.29 89.63 46.45
08:55:08 PM 126 1362 112.14 64.36 42.02
08:56:01 PM 84 1571 166.07 87.82 51.24
09:04:01 PM 91 1404 146.57 97.72 65.50
09:19:07 PM 87 1250 112.83 48.03 46.85
09:40:01 PM 87 1290 118.10 72.67 57.32
09:46:03 PM 113 1215 110.39 71.43 59.69
11:53:03 PM 101 1341 116.01 52.90 37.79
02:04:10 AM 257 1382 139.37 61.42 43.58
08:52:01 AM 84 1541 112.46 59.07 39.06
09:44:01 AM 111 1579 161.68 77.07 45.34
09:46:01 PM 105 1348 111.06 65.09 45.65
10:31:01 PM 120 1410 124.08 61.14 44.57
10:35:01 PM 83 1515 115.66 79.33 54.93
01:06:01 AM 137 1379 114.34 57.90 41.89
01:56:08 AM 216 1290 113.14 59.06 40.92
02:06:01 AM 135 1474 126.60 79.41 55.15
02:28:35 AM 267 1225 151.81 69.58 59.47
02:29:01 AM 97 1360 144.64 76.03 61.96
02:41:02 AM 144 1279 133.04 60.48 52.53
10:06:07 AM 304 1415 128.59 72.30 51.68
12:27:01 AM 121 1399 112.99 54.63 40.77
03:20:01 AM 149 1450 120.17 58.10 36.52
10:11:01 PM 136 1449 120.49 70.64 48.13
10:12:02 PM 121 1468 143.77 87.26 55.30
10:29:01 PM 64 1362 116.96 60.23 49.71
04:07:37 AM 170 1307 110.13 46.58 35.07
03:29:01 AM 97 1217 120.40 57.09 33.87
03:30:04 AM 139 1347 165.79 81.46 43.68
03:31:05 AM 105 1379 159.32 96.09 51.29
03:32:01 AM 194 1294 153.11 105.79 57.25
What I need to do is to either write the file name above each set of hours, or find a way to get the full date from sar (which from reading the man doesnt seem to be possible.) Any help would be appreciated.
An example of the desired output would be something like
/var/log/sa/sa15
2:57:01 AM 72 1318 142.61 54.60 29.89
02:58:19 AM 137 1366 135.52 71.45 37.77
01:20:10 AM 205 1246 112.29 55.22 38.40
01:22:02 AM 109 1260 195.54 102.06 57.06
01:23:01 AM 63 1219 128.44 100.63 59.44
01:26:02 AM 113 1380 120.67 99.85 65.70
01:27:02 AM 133 1371 133.72 107.76 70.58
01:28:12 AM 178 1280 120.40 108.98 73.71
03:50:02 AM 121 1443 189.25 168.81 82.88
05:56:17 AM 208 1231 113.36 41.01 20.65
05:57:06 AM 145 1227 128.45 56.78 27.11
05:58:06 AM 160 1265 149.87 74.99 35.18
05:59:01 AM 136 1370 179.49 95.48 44.45
06:00:01 AM 93 1404 156.11 105.23 51.06
/var/log/sa/sa17
06:01:01 AM 34 1310 119.41 105.12 54.48
10:07:04 AM 169 1524 110.05 82.17 55.00
10:08:01 AM 105 1466 122.00 91.18 59.82
02:26:10 AM 181 1276 149.12 62.34 34.25
02:27:05 AM 137 1327 169.27 81.70 42.43
12:02:01 AM 49 1326 110.65 57.31 39.68
07:29:02 PM 136 1279 116.35 47.18 23.75
07:30:01 PM 124 1378 116.51 58.86 29.10
07:31:03 PM 93 1200 123.80 71.66 35.50
07:32:01 PM 113 1324 138.65 84.84 42.10
07:33:01 PM 76 1411 119.29 89.63 46.45
08:55:08 PM 126 1362 112.14 64.36 42.02
08:56:01 PM 84 1571 166.07 87.82 51.24
09:04:01 PM 91 1404 146.57 97.72 65.50
09:19:07 PM 87 1250 112.83 48.03 46.85
09:40:01 PM 87 1290 118.10 72.67 57.32
09:46:03 PM 113 1215 110.39 71.43 59.69
11:53:03 PM 101 1341 116.01 52.90 37.79
02:04:10 AM 257 1382 139.37 61.42 43.58
08:52:01 AM 84 1541 112.46 59.07 39.06
09:44:01 AM 111 1579 161.68 77.07 45.34
/var/log/sa/sa19
09:46:01 PM 105 1348 111.06 65.09 45.65
10:31:01 PM 120 1410 124.08 61.14 44.57
10:35:01 PM 83 1515 115.66 79.33 54.93
01:06:01 AM 137 1379 114.34 57.90 41.89
01:56:08 AM 216 1290 113.14 59.06 40.92
02:06:01 AM 135 1474 126.60 79.41 55.15
02:28:35 AM 267 1225 151.81 69.58 59.47
02:29:01 AM 97 1360 144.64 76.03 61.96
02:41:02 AM 144 1279 133.04 60.48 52.53
10:06:07 AM 304 1415 128.59 72.30 51.68
12:27:01 AM 121 1399 112.99 54.63 40.77
03:20:01 AM 149 1450 120.17 58.10 36.52
/var/log/sa/sa20
10:11:01 PM 136 1449 120.49 70.64 48.13
10:12:02 PM 121 1468 143.77 87.26 55.30
10:29:01 PM 64 1362 116.96 60.23 49.71
04:07:37 AM 170 1307 110.13 46.58 35.07
03:29:01 AM 97 1217 120.40 57.09 33.87
03:30:04 AM 139 1347 165.79 81.46 43.68
03:31:05 AM 105 1379 159.32 96.09 51.29
03:32:01 AM 194 1294 153.11 105.79 57.25
Note that ideally it would list the filename the data was pulled from for easier tracking.
Replace
by
to print filename "$file" before sar's output.