Skip to content

Instantly share code, notes, and snippets.

@XIIIVI
Last active June 20, 2020 20:00
Show Gist options
  • Save XIIIVI/638e79d44a91e9c19d6c87b3ebe19a73 to your computer and use it in GitHub Desktop.
Save XIIIVI/638e79d44a91e9c19d6c87b3ebe19a73 to your computer and use it in GitHub Desktop.
#
# check_if_file_exists: test if the file exist and is not empty
# - param1: full qualified filename
# - param2: file type (script, configuration file, ...)
#
check_if_file_exists() {
local FILENAME=${1}
local FILE_TYPE=${2}
TEST_COUNT=$((TEST_COUNT + 1))
if [ -s "${FILENAME}" ]
then
test_succeeded "The ${FILE_TYPE} ${FILENAME} has been found"
else
local DIR_TO_LIST=$(dirname -- "${FILENAME}")
test_failed "The ${FILE_TYPE} ${FILENAME} is missing or empty"
echo -e "${YELLOW}__________________________________ ${DIR_TO_LIST} (Start) __________________________________${RESET_COLOR}"
ls -alh "${DIR_TO_LIST}"
echo -e "${YELLOW}__________________________________ ${DIR_TO_LIST} (End) __________________________________${RESET_COLOR}"
fi
}
#
# check_if_file_is_missing
# - param1: full qualified filename
# - param2: file type (script, configuration file, ...)
#
check_if_file_is_missing() {
local FILENAME=${1}
local FILE_TYPE=${2}
TEST_COUNT=$((TEST_COUNT + 1))
if [ -f "${FILENAME}" ]
then
local DIR_TO_LIST=$(dirname -- "${FILENAME}")
test_failed "The ${FILE_TYPE} ${FILENAME} has been found"
echo -e "${YELLOW}__________________________________ ${DIR_TO_LIST} (Start) __________________________________${RESET_COLOR}"
ls -alh "${DIR_TO_LIST}"
echo -e "${YELLOW}__________________________________ ${DIR_TO_LIST} (End) __________________________________${RESET_COLOR}"
else
test_succeeded "The ${FILE_TYPE} ${FILENAME} is missing"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment