Fix API breakage caused by OS Plugin version scan
[releng/global-jjb.git] / shell / sysstat.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11 echo "---> sysstat.sh"
12 set +e  # DON'T fail build if script fails.
13
14 OS=$(facter operatingsystem)
15 case "$OS" in
16     Ubuntu)
17         SYSSTAT_PATH="/var/log/sysstat"
18
19         # Dont run the script when systat is not enabled by default
20         if ! grep --quiet 'ENABLED="true"' "/etc/default/sysstat"; then
21             exit 0
22         fi
23     ;;
24     CentOS|RedHat)
25         SYSSTAT_PATH="/var/log/sa"
26     ;;
27     *)
28         # nothing to do
29         exit 0
30     ;;
31 esac
32
33 SAR_DIR="$WORKSPACE/archives/sar-reports"
34 mkdir -p "$SAR_DIR"
35 cp "$SYSSTAT_PATH/"* "$_"
36 # convert sar data to ascii format
37 while IFS="" read -r sarfilenum
38 do
39     [ -f "$sarfilenum" ] && LC_TIME=POSIX sar -A -f "$sarfilenum" > "$SAR_DIR/sar${sarfilenum//[!0-9]/}"
40 done < <(find "$SYSSTAT_PATH" -name "sa[0-9]*" || true)
41
42 # DON'T fail build if script fails.
43 exit 0