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
This commit is contained in:
Eric MacDonald 2024-06-05 09:55:03 -04:00
parent 2f17b903ce
commit 0f6cba1666

View File

@ -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