From 0f6cba1666d47f3d4f8850b459cee5fc4f3078c8 Mon Sep 17 00:00:00 2001 From: Eric MacDonald Date: Wed, 5 Jun 2024 09:55:03 -0400 Subject: [PATCH] Fix collect sysadmin plugin to support copying globs This update creates a common copy_files function that handles missing or glob copy handling modes. Test Plan: PASS: Verify copy handling when - no files match pattern - one file pattern match - several files match pattern Closes-Bug: 2068495 Change-Id: I0068e087f8867f4bafcedd7a89289da5136a29d5 --- .../collector/debian-scripts/collect_sysadmin.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tools/collector/debian-scripts/collect_sysadmin.sh b/tools/collector/debian-scripts/collect_sysadmin.sh index 5319db29..8bf3202d 100644 --- a/tools/collector/debian-scripts/collect_sysadmin.sh +++ b/tools/collector/debian-scripts/collect_sysadmin.sh @@ -14,10 +14,18 @@ source /usr/local/sbin/collect_utils SYSADMIN_DIR="${extradir}/sysadmin" mkdir -p ${SYSADMIN_DIR} -#check files exists and then copy to sysadmin directory +# Function to copy files based on pattern +copy_files() +{ + local pattern=$1 + for file in /home/sysadmin/${pattern} ; do + [ -e "${file}" ] && cp "${file}" "${SYSADMIN_DIR}/" + done +} -[ -e /home/sysadmin/*.log ] && cp /home/sysadmin/*.log /${SYSADMIN_DIR}/ -[ -e /home/sysadmin/*.yml ] && cp /home/sysadmin/*.yml /${SYSADMIN_DIR}/ -[ -e /home/sysadmin/*.yaml ] && cp /home/sysadmin/*.yaml /${SYSADMIN_DIR}/ +# get the log and yaml files from the sysadmin home dir +copy_files "*.log" +copy_files "*.yml" +copy_files "*.yaml" exit 0