Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input multiple files for SAR command

Tags:

bash

wildcard

sar

I am trying to input multiple sar files for a graph I am generating. I can input the files one at a time like so:

LC_ALL=C sar -A -f /var/log/sa/sa05 >> /tmp/sar.data3.txt

This systax does not work, but this is the idea of what I'm trying to do:

LC_ALL=C sar -A -f /var/log/sa/sa* >> /tmp/sar.data3.txt

like image 910
user3795293 Avatar asked Sep 04 '25 04:09

user3795293


2 Answers

sa* files seems to be binary files i.e. cat on one of the saXX file will not echo valid human readable words. The following can be used to see its human readable contents.

strings /var/log/sa/sa01 or saXX 

The file you might need is sarXX: you can try "LC_ALL=C ...." command as you mentioned above in place of just what I mentioned below.

for file in /var/log/sa/sar*; do sar -A -f "$file"  >> /tmp/sar.data3.txt; done

Now, the following command will show/have what you need.

cat /tmp/sar.data3.txt 

I didn't see all the options of SAR command, would recommend you to check if there is any which would support sar* or sar??

like image 69
AKS Avatar answered Sep 06 '25 05:09

AKS


You can use the find command to aggregate the files and concatenate them into your output file with something similar to:

find /var/log/sa -type f -name "sa*" \
-exec LC_ALL=C sar -A -f '{}' >> /tmp/sar.data3.txt \;

What you are attempting to do looks to be failing due to sar not accepting multiple input files with the -f option. In the future, you may consider using the -o option to prepare files containing the data you want in records that can later be output with the -f option

like image 37
David C. Rankin Avatar answered Sep 06 '25 05:09

David C. Rankin