Fix API breakage caused by OS Plugin version scan
[releng/global-jjb.git] / shell / sysstat.sh
index 03cab6d..6ecab67 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/bash
-# @License EPL-1.0 <http://spdx.org/licenses/EPL-1.0>
+# SPDX-License-Identifier: EPL-1.0
 ##############################################################################
 # Copyright (c) 2017 The Linux Foundation and others.
 #
@@ -15,6 +15,11 @@ OS=$(facter operatingsystem)
 case "$OS" in
     Ubuntu)
         SYSSTAT_PATH="/var/log/sysstat"
+
+        # Dont run the script when systat is not enabled by default
+        if ! grep --quiet 'ENABLED="true"' "/etc/default/sysstat"; then
+            exit 0
+        fi
     ;;
     CentOS|RedHat)
         SYSSTAT_PATH="/var/log/sa"
@@ -29,9 +34,9 @@ SAR_DIR="$WORKSPACE/archives/sar-reports"
 mkdir -p "$SAR_DIR"
 cp "$SYSSTAT_PATH/"* "$_"
 # convert sar data to ascii format
-while IFS="" read -r s
+while IFS="" read -r sarfilenum
 do
-    [ -f "$s" ] && LC_TIME=POSIX sar -A -f "$s" > "$SAR_DIR/sar${s//[!0-9]/}"
+    [ -f "$sarfilenum" ] && LC_TIME=POSIX sar -A -f "$sarfilenum" > "$SAR_DIR/sar${sarfilenum//[!0-9]/}"
 done < <(find "$SYSSTAT_PATH" -name "sa[0-9]*" || true)
 
 # DON'T fail build if script fails.