diff --git a/sources/lib/platform/linux/check_linux_burp_backup.sh b/sources/lib/platform/linux/check_linux_burp_backup.sh index 3c53ded..1ad05ae 100644 --- a/sources/lib/platform/linux/check_linux_burp_backup.sh +++ b/sources/lib/platform/linux/check_linux_burp_backup.sh @@ -25,6 +25,7 @@ # # @(#) HISTORY: # @(#) 2016-12-01: initial version [Patrick Van der Veken] +# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -35,7 +36,7 @@ function check_linux_burp_backup # ------------------------- CONFIGURATION starts here ------------------------- typeset _BURP_CONFIG_FILE="/etc/burp/burp-server.conf" typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" -typeset _VERSION="2016-12-01" # YYYY-MM-DD +typeset _VERSION="2018-05-21" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -145,9 +146,9 @@ do then _BACKUP_RUN="$(print ${_BACKUP_STATS} | awk '{print $1}')" # output format: YYYYMMDD HHMM - _BACKUP_DATE=$(print "${_BACKUP_STATS}" | awk '{gsub(/-/,"",$2); gsub(/:/,"",$3); print $2" "substr($3,0,4)}') + _BACKUP_DATE=$(print "${_BACKUP_STATS}" | awk '{gsub(/-/,"",$2); gsub(/:/,"",$3); print $2" "substr($3,0,4)}' 2>/dev/null) # convert to UNIX seconds - _CUR_BACKUP_TIME=$(date -d "${_BACKUP_DATE}" '+%s') + _CUR_BACKUP_TIME=$(date -d "${_BACKUP_DATE}" '+%s' 2>/dev/null) else warn "no backup found for client ${_BURP_CLIENT}. Check client impersonation?" _COUNT=$(( _COUNT + 1 )) @@ -155,7 +156,7 @@ do fi # get backup warnings - _BACKUP_WARNINGS="$(${_BURP_BIN} -c ${_BURP_CONFIG_FILE} -a S -C ${_BURP_CLIENT} -b ${_BACKUP_RUN} -z backup_stats 2>>${HC_STDERR_LOG} | grep '^warnings' 2>/dev/null | cut -f2 -d':')" + _BACKUP_WARNINGS="$(${_BURP_BIN} -c ${_BURP_CONFIG_FILE} -a S -C ${_BURP_CLIENT} -b ${_BACKUP_RUN} -z backup_stats 2>>${HC_STDERR_LOG} | grep '^warnings' 2>/dev/null | cut -f2 -d':' 2>/dev/null)" if [[ -z "${_BACKUP_WARNINGS}" ]] then warn "could not get stats for backup ${_BACKUP_RUN} of client ${_BURP_CLIENT}" diff --git a/sources/lib/platform/linux/check_linux_burp_status.sh b/sources/lib/platform/linux/check_linux_burp_status.sh index 5011570..c183a2d 100644 --- a/sources/lib/platform/linux/check_linux_burp_status.sh +++ b/sources/lib/platform/linux/check_linux_burp_status.sh @@ -24,6 +24,7 @@ # @(#) HISTORY: # @(#) 2016-12-01: initial version [Patrick Van der Veken] # @(#) 2017-05-08: fix fall-back for sysv->pgrep [Patrick Van der Veken] +# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -34,7 +35,7 @@ function check_linux_burp_status # ------------------------- CONFIGURATION starts here ------------------------- typeset _BURP_INIT_SCRIPT="/etc/init.d/burp" typeset _BURP_SYSTEMD_SERVICE="burp.service" -typeset _VERSION="2017-05-08" # YYYY-MM-DD +typeset _VERSION="2018-05-21" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -61,7 +62,7 @@ done linux_get_init case "${LINUX_INIT}" in 'systemd') - systemctl --quiet is-active ${_BURP_SYSTEMD_SERVICE} || _STC=1 + systemctl --quiet is-active ${_BURP_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=1 ;; 'upstart') warn "code for upstart managed systems not implemented, NOOP" @@ -70,7 +71,7 @@ case "${LINUX_INIT}" in 'sysv') if [[ -x ${_BURP_INIT_SCRIPT} ]] then - if (( $(${_BURP_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running') == 0 )) + if (( $(${_BURP_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running' 2>/dev/null) == 0 )) then _STC=1 fi @@ -87,7 +88,7 @@ esac # 2) try the pgrep way (note: old pgreps do not support '-c') if (( _RC != 0 )) then - (( $(pgrep -u root burp 2>>${HC_STDERR_LOG} | wc -l) == 0 )) && _STC=1 + (( $(pgrep -u root burp 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1 fi # evaluate results diff --git a/sources/lib/platform/linux/check_linux_file_age.sh b/sources/lib/platform/linux/check_linux_file_age.sh index ac4286f..acf3561 100644 --- a/sources/lib/platform/linux/check_linux_file_age.sh +++ b/sources/lib/platform/linux/check_linux_file_age.sh @@ -23,6 +23,7 @@ # # @(#) HISTORY: # @(#) 2013-05-27: initial version [Patrick Van der Veken] +# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -32,7 +33,7 @@ function check_linux_file_age { # ------------------------- CONFIGURATION starts here ------------------------- typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" -typeset _VERSION="2013-05-27" # YYYY-MM-DD +typeset _VERSION="2018-05-21" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -102,7 +103,7 @@ do _MSG="unable to read or access requested file at ${_FILE_PATH}" _STC=1 else - _AGE_CHECK=$(find "${_FILE_DIR}" -type f -name "${_FILE_NAME}" -mmin -"${_FILE_AGE}") + _AGE_CHECK=$(find "${_FILE_DIR}" -type f -name "${_FILE_NAME}" -mmin -"${_FILE_AGE}" 2>/dev/null) if (( $? != 0 )) then warn "unable to execute file age test for ${_FILE_PATH}" diff --git a/sources/lib/platform/linux/check_linux_file_change.sh b/sources/lib/platform/linux/check_linux_file_change.sh index fb17131..058f770 100644 --- a/sources/lib/platform/linux/check_linux_file_change.sh +++ b/sources/lib/platform/linux/check_linux_file_change.sh @@ -24,6 +24,7 @@ # # @(#) HISTORY: # @(#) 2017-05-18: initial version [Patrick Van der Veken] +# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -33,7 +34,7 @@ function check_linux_file_change { # ------------------------- CONFIGURATION starts here ------------------------- typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" -typeset _VERSION="2017-05-18" # YYYY-MM-DD +typeset _VERSION="2018-05-21" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -227,12 +228,12 @@ do fi # read entry from state file - _STATE_FILE_LINE=$(grep -E -e "^${_FILE_TO_CHECK}\|" ${_STATE_FILE}) + _STATE_FILE_LINE=$(grep -E -e "^${_FILE_TO_CHECK}\|" ${_STATE_FILE} 2>/dev/null) if [[ -n "${_STATE_FILE_LINE}" ]] then # field 1 is the file name - _STATE_FILE_TYPE=$(print "${_STATE_FILE_LINE}" | cut -f2 -d'|') - _STATE_FILE_CKSUM=$(print "${_STATE_FILE_LINE}" | cut -f3 -d'|') + _STATE_FILE_TYPE=$(print "${_STATE_FILE_LINE}" | cut -f2 -d'|' 2>/dev/null) + _STATE_FILE_CKSUM=$(print "${_STATE_FILE_LINE}" | cut -f3 -d'|' 2>/dev/null) else _IS_NEW=1 fi @@ -244,7 +245,7 @@ do openssl-sha256) if (( _USE_OPENSSL == 1 )) then - _FILE_CKSUM=$(${_OPENSSL_BIN} dgst -sha256 ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f2 -d'=' | tr -d ' ') + _FILE_CKSUM=$(${_OPENSSL_BIN} dgst -sha256 ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f2 -d'=' 2>/dev/null | tr -d ' ' 2>/dev/null) _FILE_TYPE="openssl-sha256" else _MSG="cannot compute checksum [${_FILE_TYPE}] for ${_FILE_TO_CHECK}" @@ -254,7 +255,7 @@ do cksum-crc32) if (( _USE_CKSUM == 1 )) then - _FILE_CKSUM=$(${_CKSUM_BIN} ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f1 -d' ') + _FILE_CKSUM=$(${_CKSUM_BIN} ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f1 -d' ' 2>/dev/null) _FILE_TYPE="cksum-crc32" else _MSG="cannot compute checksum [${_FILE_TYPE}] for ${_FILE_TO_CHECK}" @@ -270,11 +271,11 @@ do # new file if (( _USE_OPENSSL == 1 )) then - _FILE_CKSUM=$(${_OPENSSL_BIN} dgst -sha256 ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f2 -d'=' | tr -d ' ') + _FILE_CKSUM=$(${_OPENSSL_BIN} dgst -sha256 ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f2 -d'=' 2>/dev/null | tr -d ' ' 2>/dev/null) _FILE_TYPE="openssl-sha256" elif (( _USE_CKSUM == 1 )) then - _FILE_CKSUM=$(${_CKSUM_BIN} ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f1 -d' ') + _FILE_CKSUM=$(${_CKSUM_BIN} ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f1 -d' ' 2>/dev/null) _FILE_TYPE="cksum-crc32" else _MSG="cannot compute checksum (openssl/cksum) for ${_FILE_TO_CHECK}" diff --git a/sources/lib/platform/linux/check_linux_fs_mounts.sh b/sources/lib/platform/linux/check_linux_fs_mounts.sh index c16e458..3a85ebf 100644 --- a/sources/lib/platform/linux/check_linux_fs_mounts.sh +++ b/sources/lib/platform/linux/check_linux_fs_mounts.sh @@ -23,6 +23,7 @@ # # @(#) HISTORY: # @(#) 2013-05-17: initial version [Patrick Van der Veken] +# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -31,7 +32,7 @@ function check_linux_fs_mounts { # ------------------------- CONFIGURATION starts here ------------------------- -typeset _VERSION="2013-05-17" # YYYY-MM-DD +typeset _VERSION="2018-05-21" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -69,7 +70,7 @@ cat /etc/fstab |\ awk '{print $2}' |\ while read _FS do - _FS_COUNT=$(grep -c -E -e ".*on[ \t]+${_FS}[ \t]+.*" ${HC_STDOUT_LOG}) + _FS_COUNT=$(grep -c -E -e ".*on[ \t]+${_FS}[ \t]+.*" ${HC_STDOUT_LOG}) 2>/dev/null case ${_FS_COUNT} in 0) _MSG="${_FS} is not mounted" @@ -89,7 +90,7 @@ do done # add /etc/fstab to STDOUT log -cat /etc/fstab >>${HC_STDOUT_LOG} +cat /etc/fstab >>${HC_STDOUT_LOG} 2>/dev/null return 0 } diff --git a/sources/lib/platform/linux/check_linux_hpacucli.sh b/sources/lib/platform/linux/check_linux_hpacucli.sh index 3fad2c5..8ef315e 100644 --- a/sources/lib/platform/linux/check_linux_hpacucli.sh +++ b/sources/lib/platform/linux/check_linux_hpacucli.sh @@ -23,6 +23,7 @@ # # @(#) HISTORY: # @(#) 2013-09-09: initial version [Patrick Van der Veken] +# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -32,7 +33,7 @@ function check_linux_hpacucli { # ------------------------- CONFIGURATION starts here ------------------------- typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" -typeset _VERSION="2013-09-09" # YYYY-MM-DD +typeset _VERSION="2018-05-21" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -160,9 +161,9 @@ then print "=== ACU controller(s) ===" >>${HC_STDOUT_LOG} cat ${_TMP_FILE} >>${HC_STDOUT_LOG} # get all slot numbers for multiple raid controllers - cat ${_TMP_FILE} | grep "in Slot [0-9]" | while read _ACU_LINE + cat ${_TMP_FILE} | grep "in Slot [0-9]" 2>/dev/null | while read _ACU_LINE do - _SLOT_NUM="$(print ${_ACU_LINE} | cut -f6 -d' ')" + _SLOT_NUM="$(print ${_ACU_LINE} | cut -f6 -d' ' 2>/dev/null)" case "${_DO_ACU_LOGL}" in +([0-9])*([0-9])) # numeric OK diff --git a/sources/lib/platform/linux/check_linux_hpasmcli.sh b/sources/lib/platform/linux/check_linux_hpasmcli.sh index b1458b1..12d980b 100644 --- a/sources/lib/platform/linux/check_linux_hpasmcli.sh +++ b/sources/lib/platform/linux/check_linux_hpasmcli.sh @@ -24,6 +24,7 @@ # @(#) HISTORY: # @(#) 2013-09-07: initial version [Patrick Van der Veken] # @(#) 2017-04-06: bugfix in temperature checking [Patrick Van der Veken] +# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -33,7 +34,7 @@ function check_linux_hpasmcli { # ------------------------- CONFIGURATION starts here ------------------------- typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" -typeset _VERSION="2017-04-06" # YYYY-MM-DD +typeset _VERSION="2018-05-21" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -157,7 +158,7 @@ then ${_HPASMCLI_BIN} -s 'SHOW FANS' >${_TMP_FILE} 2>${_TMP_FILE} (( $? != 0 )) && warn "'${_HPASMCLI_BIN} -s SHOW FANS' exited non-zero" # look for failures - grep -E -e '^#' ${_TMP_FILE} 2>/dev/null | grep -vi 'normal' |\ + grep -E -e '^#' ${_TMP_FILE} 2>/dev/null | grep -vi 'normal' 2>/dev/null |\ while read _ASM_LINE do _FAN_UNIT="$(print ${_ASM_LINE} | cut -f1 -d' ')" @@ -241,15 +242,15 @@ then grep -E -e '^#' ${_TMP_FILE} 2>/dev/null |\ while read _ASM_LINE do - _TEMP_FIELD="$(print ${_ASM_LINE} | cut -f3 -d' ')" + _TEMP_FIELD="$(print ${_ASM_LINE} | cut -f3 -d' ' 2>/dev/null)" _TEMP_VALUE="${_TEMP_FIELD%%C/*}" - _THRES_FIELD="$(print ${_ASM_LINE} | cut -f4 -d' ')" + _THRES_FIELD="$(print ${_ASM_LINE} | cut -f4 -d' ' 2>/dev/null)" _THRES_VALUE="${_THRES_FIELD%%C/*}" if [[ "${_TEMP_VALUE}" != "-" ]] && [[ "${_THRES_VALUE}" != "-" ]] then if (( _TEMP_VALUE >= _THRES_VALUE )) then - _TEMP_UNIT="$(print ${_ASM_LINE} | cut -f1 -d' ')" + _TEMP_UNIT="$(print ${_ASM_LINE} | cut -f1 -d' ' 2>/dev/null)" _MSG="failure in 'SHOW TEMP', unit ${_TEMP_UNIT}" _MSG="${_MSG} has ${_TEMP_VALUE} >= ${_THRES_VALUE}" _STC_COUNT=$(( _STC_COUNT + 1 )) diff --git a/sources/lib/platform/linux/check_linux_hplog.sh b/sources/lib/platform/linux/check_linux_hplog.sh index 37b9dcd..1f31fdd 100644 --- a/sources/lib/platform/linux/check_linux_hplog.sh +++ b/sources/lib/platform/linux/check_linux_hplog.sh @@ -19,10 +19,11 @@ # @(#) MAIN: check_linux_hplog # DOES: see _show_usage() # EXPECTS: see _show_usage() -# REQUIRES: data_space2comma(), init_hc(), log_hc() +# REQUIRES: data_space2comma(), dump_logs(), init_hc(), log_hc() # # @(#) HISTORY: # @(#) 2017-04-22: initial version [Patrick Van der Veken] +# @(#) 2018-05-21: added dump_logs() & STDERR fixes [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -33,7 +34,7 @@ function check_linux_hplog # ------------------------- CONFIGURATION starts here ------------------------- typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" typeset _STATE_FILE="${STATE_PERM_DIR}/discovered.hplog" -typeset _VERSION="2017-04-22" # YYYY-MM-DD +typeset _VERSION="2018-05-21" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -90,7 +91,7 @@ then else # build the complex search regex _HPLOG_SEVERITIES="^" - print "${_SEVERITIES_LINE}" | tr ',' '\n' | while read -r _SEVERITY_ENTRY + print "${_SEVERITIES_LINE}" | tr ',' '\n' 2>/dev/null | while read -r _SEVERITY_ENTRY do _HPLOG_SEVERITIES="${_HPLOG_SEVERITIES}(([0-9]+)\s*${_SEVERITY_ENTRY})|" done @@ -110,6 +111,8 @@ ${_HPLOG_BIN} -v >${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} (( $? != 0 )) && { _MSG="unable to run ${_HPLOG_BIN}" log_hc "$0" 1 "${_MSG}" + # dump debug info + (( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs return 0 } @@ -143,7 +146,7 @@ then _MSG="found ${_STC_COUNT} new HPLOG messages {${_HPLOG_BIN} -v}" _STC=1 # add results to state file (must be sorted; re-use TMP_FILE) - sort -u ${_TMP1_FILE} ${_TMP2_FILE} > ${_STATE_FILE} + sort -u ${_TMP1_FILE} ${_TMP2_FILE} >${_STATE_FILE} 2>/dev/null (( $? > 0 )) && { warn "failed to sort temporary state file" return 1 diff --git a/sources/lib/platform/linux/check_linux_hpssacli.sh b/sources/lib/platform/linux/check_linux_hpssacli.sh index 33885a4..a52d82b 100644 --- a/sources/lib/platform/linux/check_linux_hpssacli.sh +++ b/sources/lib/platform/linux/check_linux_hpssacli.sh @@ -23,6 +23,7 @@ # # @(#) HISTORY: # @(#) 2016-04-01: initial version [Patrick Van der Veken] +# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -32,7 +33,7 @@ function check_linux_hpssacli { # ------------------------- CONFIGURATION starts here ------------------------- typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" -typeset _VERSION="2016-04-01" # YYYY-MM-DD +typeset _VERSION="2018-05-21" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -160,9 +161,9 @@ then print "=== SSA controller(s) ===" >>${HC_STDOUT_LOG} cat ${_TMP_FILE} >>${HC_STDOUT_LOG} # get all slot numbers for multiple raid controllers - cat ${_TMP_FILE} | grep "in Slot [0-9]" | while read _SSA_LINE + cat ${_TMP_FILE} | grep "in Slot [0-9]" 2>/dev/null | while read _SSA_LINE do - _SLOT_NUM="$(print ${_SSA_LINE} | cut -f6 -d' ')" + _SLOT_NUM="$(print ${_SSA_LINE} | cut -f6 -d' ' 2>/dev/null)" case "${_DO_SSA_LOGL}" in +([0-9])*([0-9])) # numeric OK diff --git a/sources/lib/platform/linux/check_linux_httpd_status.sh b/sources/lib/platform/linux/check_linux_httpd_status.sh index 728348c..6f87429 100644 --- a/sources/lib/platform/linux/check_linux_httpd_status.sh +++ b/sources/lib/platform/linux/check_linux_httpd_status.sh @@ -25,6 +25,7 @@ # @(#) 2017-04-23: initial version [Patrick Van der Veken] # @(#) 2017-05-08: fix fall-back for sysv->pgrep [Patrick Van der Veken] # @(#) 2017-05-17: removed _MSG dupe [Patrick Van der Veken] +# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -35,7 +36,7 @@ function check_linux_httpd_status # ------------------------- CONFIGURATION starts here ------------------------- typeset _HTTPD_INIT_SCRIPT="/etc/init.d/httpd" typeset _HTTPD_SYSTEMD_SERVICE="httpd.service" -typeset _VERSION="2017-05-17" # YYYY-MM-DD +typeset _VERSION="2018-05-21" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -64,7 +65,7 @@ done linux_get_init case "${LINUX_INIT}" in 'systemd') - systemctl --quiet is-active ${_HTTPD_SYSTEMD_SERVICE} || _STC=1 + systemctl --quiet is-active ${_HTTPD_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=1 ;; 'upstart') warn "code for upstart managed systems not implemented, NOOP" @@ -74,7 +75,7 @@ case "${LINUX_INIT}" in # check running SysV if [[ -x ${_HTTPD_INIT_SCRIPT} ]] then - if (( $(${_HTTPD_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running') == 0 )) + if (( $(${_HTTPD_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running' 2>/dev/null) == 0 )) then _STC=1 fi @@ -91,7 +92,7 @@ esac # 2) try the pgrep way (note: old pgreps do not support '-c') if (( _RC != 0 )) then - (( $(pgrep -u root httpd 2>>${HC_STDERR_LOG} | wc -l) == 0 )) && _STC=1 + (( $(pgrep -u root httpd 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1 fi # evaluate results diff --git a/sources/lib/platform/linux/check_linux_named_status.sh b/sources/lib/platform/linux/check_linux_named_status.sh index b4680da..5a2adbd 100644 --- a/sources/lib/platform/linux/check_linux_named_status.sh +++ b/sources/lib/platform/linux/check_linux_named_status.sh @@ -24,6 +24,7 @@ # @(#) HISTORY: # @(#) 2013-12-01: initial version [Patrick Van der Veken] # @(#) 2017-05-08: fix fall-back for sysv->pgrep [Patrick Van der Veken] +# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -32,7 +33,7 @@ function check_linux_named_status { # ------------------------- CONFIGURATION starts here ------------------------- -typeset _VERSION="2017-05-08" # YYYY-MM-DD +typeset _VERSION="2018-05-21" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -75,7 +76,7 @@ esac linux_get_init case "${LINUX_INIT}" in 'systemd') - systemctl --quiet is-active ${_NAMED_SYSTEMD_SERVICE} || _STC=1 + systemctl --quiet is-active ${_NAMED_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=1 ;; 'upstart') warn "code for upstart managed systems not implemented, NOOP" @@ -85,7 +86,7 @@ case "${LINUX_INIT}" in # check running named if [[ -x ${_NAMED_INIT_SCRIPT} ]] then - if (( $(${_NAMED_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running') == 0 )) + if (( $(${_NAMED_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running' 2>/dev/null) == 0 )) then _STC=1 fi @@ -102,7 +103,7 @@ esac # 2) try the pgrep way (note: old pgreps do not support '-c') if (( _RC != 0 )) then - (( $(pgrep -u root named 2>>${HC_STDERR_LOG} | wc -l) == 0 )) && _STC=1 + (( $(pgrep -u root named 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1 fi # evaluate results diff --git a/sources/lib/platform/linux/check_linux_ntp_status.sh b/sources/lib/platform/linux/check_linux_ntp_status.sh index 7414ce0..5408893 100644 --- a/sources/lib/platform/linux/check_linux_ntp_status.sh +++ b/sources/lib/platform/linux/check_linux_ntp_status.sh @@ -23,6 +23,7 @@ # # @(#) HISTORY: # @(#) 2018-03-20: initial version [Patrick Van der Veken] +# @(#) 2018-05-21: STDERR + other small fixes [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #------------------------------------------------------------------------------ @@ -34,7 +35,7 @@ function check_linux_ntp_status typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" typeset _NTPD_INIT_SCRIPT="/etc/init.d/ntpd" typeset _NTPD_SYSTEMD_SERVICE="ntpd.service" -typeset _VERSION="2018-03-20" # YYYY-MM-DD +typeset _VERSION="2018-05-21" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match typeset _NTPQ_BIN="/usr/sbin/ntpq" # ------------------------- CONFIGURATION ends here --------------------------- @@ -80,7 +81,7 @@ fi linux_get_init case "${LINUX_INIT}" in 'systemd') - systemctl --quiet is-active ${_NTPD_SYSTEMD_SERVICE} || _STC=1 + systemctl --quiet is-active ${_NTPD_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=1 ;; 'upstart') warn "code for upstart managed systems not implemented, NOOP" @@ -90,7 +91,7 @@ case "${LINUX_INIT}" in # check running SysV if [[ -x ${_NTPD_INIT_SCRIPT} ]] then - if (( $(${_NTPD_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running') == 0 )) + if (( $(${_NTPD_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running' 2>/dev/null) == 0 )) then _STC=1 fi @@ -107,13 +108,13 @@ esac # evaluate results case ${_STC} in 0) - _MSG="postfix is running" + _MSG="ntpd is running" ;; 1) - _MSG="postfix is not running" + _MSG="ntpd is not running" ;; *) - _MSG="could not determine status of postfix" + _MSG="could not determine status of n" ;; esac log_hc "$0" ${_STC} "${_MSG}" @@ -131,7 +132,7 @@ else fi # 1) active server -_NTP_PEER="$(grep -E -e '^\*' 2>/dev/null ${HC_STDOUT_LOG} | awk '{ print $1 }')" +_NTP_PEER="$(grep -E -e '^\*' 2>/dev/null ${HC_STDOUT_LOG} | awk '{ print $1 }') 2>/dev/null" case ${_NTP_PEER} in \*127.127.1.0*) _MSG="NTP is synchronizing against its internal clock" @@ -151,11 +152,11 @@ log_hc "$0" ${_STC} "${_MSG}" # 2) offset value if (( _STC == 0 )) then - _CURR_OFFSET="$(grep -E -e '^\*' 2>/dev/null ${HC_STDOUT_LOG} | awk '{ print $9 }')" + _CURR_OFFSET="$(grep -E -e '^\*' 2>/dev/null ${HC_STDOUT_LOG} | awk '{ print $9 }') 2>/dev/null" case ${_CURR_OFFSET} in +([-0-9])*(.)*([0-9])) # numeric, OK (negatives are OK too!) - if (( $(awk -v c="${_CURR_OFFSET}" -v m="${_MAX_OFFSET}" 'BEGIN { print (c>m) }') != 0 )) + if (( $(awk -v c="${_CURR_OFFSET}" -v m="${_MAX_OFFSET}" 'BEGIN { print (c>m) }' 2>/dev/null) != 0 )) then _MSG="NTP offset of ${_CURR_OFFSET} is bigger than the configured maximum of ${_MAX_OFFSET}" _STC=1 diff --git a/sources/lib/platform/linux/check_linux_postfix_status.sh b/sources/lib/platform/linux/check_linux_postfix_status.sh index b70ab5c..18829ce 100644 --- a/sources/lib/platform/linux/check_linux_postfix_status.sh +++ b/sources/lib/platform/linux/check_linux_postfix_status.sh @@ -25,6 +25,7 @@ # @(#) 2016-12-01: initial version [Patrick Van der Veken] # @(#) 2017-05-08: suppress errors on postfix call + fix fall-back # @(#) for sysv->pgrep[Patrick Van der Veken] +# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -35,7 +36,7 @@ function check_linux_postfix_status # ------------------------- CONFIGURATION starts here ------------------------- typeset _POSTFIX_INIT_SCRIPT="/etc/init.d/postfix" typeset _POSTFIX_SYSTEMD_SERVICE="postfix.service" -typeset _VERSION="2017-05-08" # YYYY-MM-DD +typeset _VERSION="2018-05-21" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -63,7 +64,7 @@ done linux_get_init case "${LINUX_INIT}" in 'systemd') - systemctl --quiet is-active ${_POSTFIX_SYSTEMD_SERVICE} || _STC=1 + systemctl --quiet is-active ${_POSTFIX_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=1 ;; 'upstart') warn "code for upstart managed systems not implemented, NOOP" @@ -73,7 +74,7 @@ case "${LINUX_INIT}" in # check running SysV if [[ -x ${_POSTFIX_INIT_SCRIPT} ]] then - if (( $(${_POSTFIX_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running') == 0 )) + if (( $(${_POSTFIX_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running' 2>/dev/null) == 0 )) then _STC=1 fi @@ -93,7 +94,7 @@ then _POSTFIX_BIN="$(which postfix 2>>${HC_STDERR_LOG})" if [[ -x ${_POSTFIX_BIN} && -n "${_POSTFIX_BIN}" ]] then - if (( $(${_POSTFIX_BIN} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running') == 0 )) + if (( $(${_POSTFIX_BIN} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running' 2>/dev/null) == 0 )) then _STC=1 fi diff --git a/sources/lib/platform/linux/check_linux_root_crontab.sh b/sources/lib/platform/linux/check_linux_root_crontab.sh index d7140d9..f687a1e 100644 --- a/sources/lib/platform/linux/check_linux_root_crontab.sh +++ b/sources/lib/platform/linux/check_linux_root_crontab.sh @@ -23,6 +23,7 @@ # # @(#) HISTORY: # @(#) 2013-09-19: initial version [Patrick Van der Veken] +# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -32,7 +33,7 @@ function check_linux_root_crontab { # ------------------------- CONFIGURATION starts here ------------------------- typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" -typeset _VERSION="2013-09-19" # YYYY-MM-DD +typeset _VERSION="2018-05-21" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -85,7 +86,7 @@ if [[ -d /etc/cron.d ]] then cat /etc/cron.d/* | while read _CRON_LINE do - if [[ $(print "${_CRON_LINE}" | awk '{print $6}') == "root" ]] + if [[ $(print "${_CRON_LINE}" | awk '{print $6}' 2>/dev/null) == "root" ]] then print "${_CRON_LINE}" >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} fi @@ -96,7 +97,7 @@ fi grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | while read _CRON_ENTRY do _CRON_MATCH=$(grep -v '^#' ${HC_STDOUT_LOG} 2>/dev/null |\ - grep -c -E -e "${_CRON_ENTRY}") + grep -c -E -e "${_CRON_ENTRY}" 2>/dev/null) case ${_CRON_MATCH} in 0) _MSG="'${_CRON_ENTRY}' is not configured in cron" diff --git a/sources/lib/platform/linux/check_linux_samba_status.sh b/sources/lib/platform/linux/check_linux_samba_status.sh index b1c01bc..e3c2901 100644 --- a/sources/lib/platform/linux/check_linux_samba_status.sh +++ b/sources/lib/platform/linux/check_linux_samba_status.sh @@ -26,6 +26,7 @@ # @(#) 2016-12-01: added systemd code [Patrick Van der Veken] # @(#) 2017-05-08: fix fall-back for sysv->pgrep [Patrick Van der Veken] # @(#) 2017-07-23: fix for systemd service names [Patrick Van der Veken] +# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -37,7 +38,7 @@ function check_linux_samba_status typeset _SMB_INIT_SCRIPT="/etc/init.d/samba" typeset _SMB_SYSTEMD_SERVICE="smb.service" typeset _NMB_SYSTEMD_SERVICE="nmb.service" -typeset _VERSION="2017-07-23" # YYYY-MM-DD +typeset _VERSION="2018-05-21" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -65,9 +66,9 @@ linux_get_init case "${LINUX_INIT}" in 'systemd') # check running NMB - systemctl --quiet is-active ${_NMB_SYSTEMD_SERVICE} || _STC=1 + systemctl --quiet is-active ${_NMB_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=1 # check running SMB - systemctl --quiet is-active ${_SMB_SYSTEMD_SERVICE} || _STC=$(( _STC + 2 )) + systemctl --quiet is-active ${_SMB_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=$(( _STC + 2 )) ;; 'upstart') warn "code for upstart managed systems not implemented, NOOP" @@ -77,12 +78,12 @@ case "${LINUX_INIT}" in # check running NMB/SMB if [[ -x ${_SMB_INIT_SCRIPT} ]] then - if (( $(${_SMB_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i -E -e 'NMB.*is running.*') == 0 )) + if (( $(${_SMB_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i -E -e 'NMB.*is running.*' 2>/dev/null) == 0 )) then _STC=1 fi # check running SMB - if (( $(${_SMB_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i -E -e 'SMB.*is running.*') == 0 )) + if (( $(${_SMB_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i -E -e 'SMB.*is running.*' 2>/dev/null) == 0 )) then _STC=$(( _STC + 2 )) fi @@ -99,8 +100,8 @@ esac # 2) try the pgrep way (note: old pgreps do not support '-c') if (( _RC != 0 )) then - (( $(pgrep -u root nmbd 2>>${HC_STDERR_LOG}| wc -l) == 0 )) && _STC=1 - (( $(pgrep -u root smbd 2>>${HC_STDERR_LOG} | wc -l) == 0 )) && _STC=$(( _STC + 2 )) + (( $(pgrep -u root nmbd 2>>${HC_STDERR_LOG}| wc -l 2>/dev/null) == 0 )) && _STC=1 + (( $(pgrep -u root smbd 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=$(( _STC + 2 )) fi # evaluate results diff --git a/sources/lib/platform/linux/check_linux_sg_cluster_config.sh b/sources/lib/platform/linux/check_linux_sg_cluster_config.sh index d73195d..a1a9fc4 100644 --- a/sources/lib/platform/linux/check_linux_sg_cluster_config.sh +++ b/sources/lib/platform/linux/check_linux_sg_cluster_config.sh @@ -19,10 +19,11 @@ # @(#) MAIN: check_linux_sg_cluster_status # DOES: see _show_usage() # EXPECTS: see _show_usage() -# REQUIRES: data_space2comma(), init_hc(), log_hc(), warn() +# REQUIRES: data_space2comma(), dump_logs(), init_hc(), log_hc(), warn() # # @(#) HISTORY: # @(#) 2017-04-01: initial version [Patrick Van der Veken] +# @(#) 2018-05-21: added dump_logs() & other fixes [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -32,7 +33,7 @@ function check_linux_sg_cluster_config { # ------------------------- CONFIGURATION starts here ------------------------- typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" -typeset _VERSION="2017-04-01" # YYYY-MM-DD +typeset _VERSION="2018-05-21" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match typeset _SG_DAEMON="/opt/cmcluster/bin/cmcld" # rubbish that cmgetconf outputs to STDOUT instead of STDERR @@ -79,7 +80,7 @@ then fi # look for cluster instance names -grep -E -e '^\[' ${_CONFIG_FILE} 2>/dev/null | cut -f1 -d']' | cut -f2 -d'[' |\ +grep -E -e '^\[' ${_CONFIG_FILE} 2>/dev/null | cut -f1 -d']' 2>/dev/null | cut -f2 -d'[' 2>/dev/null |\ while read _CLUSTER_INSTANCE do _CLUSTER_INSTANCES="${_CLUSTER_INSTANCES} ${_CLUSTER_INSTANCE}" @@ -103,6 +104,8 @@ else [[ -s ${_CLUSTER_RUN_FILE}.${_CLUSTER_INSTANCE} ]] || { _MSG="unable to gather cluster configuration" log_hc "$0" 1 "${_MSG}" + # dump debug info + (( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs return 0 } done @@ -142,11 +145,11 @@ do while read _CLUSTER_ENTRY do # split entry to get the compressed version - _CLUSTER_CFG_ENTRY=$(print "${_CLUSTER_ENTRY}" | cut -f2 -d'|') + _CLUSTER_CFG_ENTRY=$(print "${_CLUSTER_ENTRY}" | cut -f2 -d'|' 2>/dev/null) # get parameter name from non-compressed version - _CLUSTER_PARAM=$(print "${_CLUSTER_ENTRY}" | cut -f1 -d'|' | awk '{ print $1 }') + _CLUSTER_PARAM=$(print "${_CLUSTER_ENTRY}" | cut -f1 -d'|' 2>/dev/null | awk '{ print $1 }' 2>/dev/null) # get parameter value from non-compressed version - _CLUSTER_VALUE=$(print "${_CLUSTER_ENTRY}" | cut -f1 -d'|' | awk '{ print substr($2,1,30)}') + _CLUSTER_VALUE=$(print "${_CLUSTER_ENTRY}" | cut -f1 -d'|' 2>/dev/null | awk '{ print substr($2,1,30)}' 2>/dev/null) # is it present? _CLUSTER_MATCH=$(grep -c "${_CLUSTER_CFG_ENTRY}" ${_CLUSTER_RUN_FILE}.${_CLUSTER_INSTANCE} 2>/dev/null) if (( _CLUSTER_MATCH == 0 )) diff --git a/sources/lib/platform/linux/check_linux_sg_cluster_status.sh b/sources/lib/platform/linux/check_linux_sg_cluster_status.sh index d684a69..0bbe16b 100644 --- a/sources/lib/platform/linux/check_linux_sg_cluster_status.sh +++ b/sources/lib/platform/linux/check_linux_sg_cluster_status.sh @@ -25,6 +25,7 @@ # @(#) 2017-04-01: initial version [Patrick Van der Veken] # @(#) 2017-05-07: made checks more detailed for log_hc() [Patrick Van der Veken] # @(#) 2018-05-20: added dump_logs() [Patrick Van der Veken] +# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -34,7 +35,7 @@ function check_linux_sg_cluster_status { # ------------------------- CONFIGURATION starts here ------------------------- typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" -typeset _VERSION="2018-05-20" # YYYY-MM-DD +typeset _VERSION="2018-05-21" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match typeset _SG_DAEMON="/opt/cmcluster/bin/cmcld" # ------------------------- CONFIGURATION ends here --------------------------- @@ -78,7 +79,7 @@ then warn "${_SG_DAEMON} is not installed here" return 1 else - cmviewcl -v -f line 2>>${HC_STDERR_LOG} | tr '|' ':' >>${HC_STDOUT_LOG} + cmviewcl -v -f line 2>>${HC_STDERR_LOG} | tr '|' ':' >>${HC_STDOUT_LOG} 2>/dev/null (( $? != 0 )) && { _MSG="unable to run command: {cmviewcl}" log_hc "$0" 1 "${_MSG}" @@ -90,17 +91,18 @@ fi # do cluster status checks # (replace ':' by '|' for cmcviewcl output) -grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | tr '|' ':' | while read _SG_ENTRY +grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | tr '|' ':' 2>/dev/null |\ + while read _SG_ENTRY do # field split - _SG_CFG_PARAM="$(print ${_SG_ENTRY} | cut -f1 -d'=')" # field 1 - _SG_CFG_VALUE="$(print ${_SG_ENTRY} | cut -f2 -d'=')" # field 2 + _SG_CFG_PARAM="$(print ${_SG_ENTRY} | cut -f1 -d'=' 2>/dev/null)" # field 1 + _SG_CFG_VALUE="$(print ${_SG_ENTRY} | cut -f2 -d'=' 2>/dev/null)" # field 2 # check run-time values (anchored grep here!) _SG_MATCH=$(grep -i "^${_SG_CFG_PARAM}" ${HC_STDOUT_LOG} 2>/dev/null) if [[ -n "${_SG_MATCH}" ]] then - _SG_RUN_VALUE=$(print "${_SG_MATCH}" | cut -f2 -d'=') # field 2 + _SG_RUN_VALUE=$(print "${_SG_MATCH}" | cut -f2 -d'=' 2>/dev/null) # field 2 if [[ "${_SG_CFG_VALUE}" = "${_SG_RUN_VALUE}" ]] then diff --git a/sources/lib/platform/linux/check_linux_sg_package_config.sh b/sources/lib/platform/linux/check_linux_sg_package_config.sh index 3f67867..4ff981d 100644 --- a/sources/lib/platform/linux/check_linux_sg_package_config.sh +++ b/sources/lib/platform/linux/check_linux_sg_package_config.sh @@ -19,10 +19,11 @@ # @(#) MAIN: check_linux_sg_package_config # DOES: see _show_usage() # EXPECTS: see _show_usage() -# REQUIRES: data_space2comma(), init_hc(), log_hc(), warn() +# REQUIRES: data_space2comma(), dump_logs(), init_hc(), log_hc(), warn() # # @(#) HISTORY: # @(#) 2017-04-01: initial version [Patrick Van der Veken] +# @(#) 2018-05-21: added dump_logs() & other fixes [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -32,7 +33,7 @@ function check_linux_sg_package_config { # ------------------------- CONFIGURATION starts here ------------------------- typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" -typeset _VERSION="2017-04-01" # YYYY-MM-DD +typeset _VERSION="2018-05-21" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match typeset _SG_DAEMON="/opt/cmcluster/bin/cmcld" # rubbish that cmgetconf outputs to STDOUT instead of STDERR @@ -79,7 +80,7 @@ then fi # look for package instance names -grep -E -e '^\[' ${_CONFIG_FILE} 2>/dev/null | cut -f1 -d']' | cut -f2 -d'[' |\ +grep -E -e '^\[' ${_CONFIG_FILE} 2>/dev/null | cut -f1 -d']' 2>/dev/null | cut -f2 -d'[' 2>/dev/null |\ while read _PKG_INSTANCE do _PKG_INSTANCES="${_PKG_INSTANCES} ${_PKG_INSTANCE}" @@ -103,6 +104,8 @@ else [[ -s ${_PKG_RUN_FILE}.${_PKG_INSTANCE} ]] || { _MSG="unable to gather package configuration for at least one cluster package" log_hc "$0" 1 "${_MSG}" + # dump debug info + (( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs return 0 } done @@ -142,11 +145,11 @@ do while read _PKG_ENTRY do # split entry to get the compressed version - _PKG_CFG_ENTRY=$(print "${_PKG_ENTRY}" | cut -f2 -d'|') + _PKG_CFG_ENTRY=$(print "${_PKG_ENTRY}" | cut -f2 -d'|' 2>/dev/null) # get parameter name from non-compressed version - _PKG_PARAM=$(print "${_PKG_ENTRY}" | awk '{ print $1 }') + _PKG_PARAM=$(print "${_PKG_ENTRY}" | awk '{ print $1 }' 2>/dev/null) # get parameter value from non-compressed version - _PKG_VALUE=$(print "${_PKG_ENTRY}" | cut -f1 -d'|' | awk '{ print substr($2,1,30)}') + _PKG_VALUE=$(print "${_PKG_ENTRY}" | cut -f1 -d'|' 2>/dev/null| awk '{ print substr($2,1,30)}' 2>/dev/null) # is it present? _PKG_MATCH=$(grep -c "${_PKG_CFG_ENTRY}" ${_PKG_RUN_FILE}.${_PKG_INSTANCE} 2>/dev/null) if (( _PKG_MATCH == 0 )) diff --git a/sources/lib/platform/linux/check_linux_sg_package_status.sh b/sources/lib/platform/linux/check_linux_sg_package_status.sh index 3d6f3e1..dfc8a1a 100644 --- a/sources/lib/platform/linux/check_linux_sg_package_status.sh +++ b/sources/lib/platform/linux/check_linux_sg_package_status.sh @@ -25,6 +25,7 @@ # @(#) 2017-04-01: initial version [Patrick Van der Veken] # @(#) 2017-05-07: made checks more detailed for log_hc() [Patrick Van der Veken] # @(#) 2018-05-20: added dump_logs() [Patrick Van der Veken] +# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -34,7 +35,7 @@ function check_linux_sg_package_status { # ------------------------- CONFIGURATION starts here ------------------------- typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" -typeset _VERSION="2018-05-20" # YYYY-MM-DD +typeset _VERSION="2018-05-21" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match typeset _SG_DAEMON="/opt/cmcluster/bin/cmcld" # ------------------------- CONFIGURATION ends here --------------------------- @@ -91,18 +92,18 @@ fi # do package status checks # (replace ':' by '|' for cmcviewcl output) -grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | tr '|' ':' | while read _SG_ENTRY +grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | tr '|' ':' 2>/dev/null | while read _SG_ENTRY do # field split _SG_PACKAGE="$(print ${_SG_ENTRY} | cut -f1 -d':')" - _SG_CFG_PARAM="$(print ${_SG_ENTRY} | cut -f2- -d':' | cut -f1 -d'=')" # field 2-,1 - _SG_CFG_VALUE="$(print ${_SG_ENTRY} | cut -f2- -d':' | cut -f2 -d'=')" # field 2-,2 + _SG_CFG_PARAM="$(print ${_SG_ENTRY} | cut -f2- -d':' 2>/dev/null | cut -f1 -d'=' 2>/dev/null)" # field 2-,1 + _SG_CFG_VALUE="$(print ${_SG_ENTRY} | cut -f2- -d':' 2>/dev/null | cut -f2 -d'=' 2>/dev/null)" # field 2-,2 # check run-time values (anchored grep here!) _SG_MATCH=$(grep -i "^package:${_SG_PACKAGE}:${_SG_CFG_PARAM}" ${HC_STDOUT_LOG} 2>/dev/null) if [[ -n "${_SG_MATCH}" ]] then - _SG_RUN_VALUE=$(print "${_SG_MATCH}" | cut -f3- -d':' | cut -f2 -d'=') # field3-,2 + _SG_RUN_VALUE=$(print "${_SG_MATCH}" | cut -f3- -d':' 2>/dev/null | cut -f2 -d'=' 2>/dev/null) # field3-,2 if [[ "${_SG_CFG_VALUE}" = "${_SG_RUN_VALUE}" ]] then diff --git a/sources/lib/platform/linux/check_linux_sg_qs_status.sh b/sources/lib/platform/linux/check_linux_sg_qs_status.sh index efad74b..183b6bd 100644 --- a/sources/lib/platform/linux/check_linux_sg_qs_status.sh +++ b/sources/lib/platform/linux/check_linux_sg_qs_status.sh @@ -23,6 +23,7 @@ # # @(#) HISTORY: # @(#) 2017-05-01: initial version [Patrick Van der Veken] +# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -31,7 +32,7 @@ function check_linux_sg_qs_status { # ------------------------- CONFIGURATION starts here ------------------------- -typeset _VERSION="2017-05-01" # YYYY-MM-DD +typeset _VERSION="2018-05-1" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match typeset _QS_BIN="/opt/qs/bin/qsc" typeset _QS_AUTH_FILE="/opt/qs/conf/qs_authfile" @@ -64,7 +65,7 @@ then fi # ---- process state ---- -(( $(pgrep -u root -f ${_QS_BIN} 2>>${HC_STDERR_LOG} | wc -l) == 0 )) && _STC=1 +(( $(pgrep -u root -f ${_QS_BIN} 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1 # evaluate results case ${_STC} in diff --git a/sources/lib/platform/linux/check_linux_sshd_status.sh b/sources/lib/platform/linux/check_linux_sshd_status.sh index 9b2b770..568057b 100644 --- a/sources/lib/platform/linux/check_linux_sshd_status.sh +++ b/sources/lib/platform/linux/check_linux_sshd_status.sh @@ -25,6 +25,7 @@ # @(#) 2016-12-01: initial version [Patrick Van der Veken] # @(#) 2017-05-05: fix fall-back for sysv->pgrep [Patrick Van der Veken] # @(#) 2017-05-08: set init/systemd based on distro [Patrick Van der Veken] +# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -33,7 +34,7 @@ function check_linux_sshd_status { # ------------------------- CONFIGURATION starts here ------------------------- -typeset _VERSION="2017-05-08" # YYYY-MM-DD +typeset _VERSION="2018-05-21" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -74,7 +75,7 @@ esac linux_get_init case "${LINUX_INIT}" in 'systemd') - systemctl --quiet is-active ${_SSHD_SYSTEMD_SERVICE} || _STC=1 + systemctl --quiet is-active ${_SSHD_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=1 ;; 'upstart') warn "code for upstart managed systems not implemented, NOOP" @@ -83,7 +84,7 @@ case "${LINUX_INIT}" in 'sysv') if [[ -x ${_SSHD_INIT_SCRIPT} ]] then - if (( $(${_SSHD_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running') == 0 )) + if (( $(${_SSHD_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running' 2>/dev/null) == 0 )) then _STC=1 fi @@ -100,7 +101,7 @@ esac # 2) try the pgrep way (note: old pgreps do not support '-c') if (( _RC != 0 )) then - (( $(pgrep -P 1 -u root sshd 2>>${HC_STDERR_LOG} | wc -l) == 0 )) && _STC=1 + (( $(pgrep -P 1 -u root sshd 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1 fi # evaluate results diff --git a/sources/lib/platform/linux/check_linux_vz_ct_status.sh b/sources/lib/platform/linux/check_linux_vz_ct_status.sh index 610518e..520e178 100644 --- a/sources/lib/platform/linux/check_linux_vz_ct_status.sh +++ b/sources/lib/platform/linux/check_linux_vz_ct_status.sh @@ -27,6 +27,7 @@ # @(#) 2017-06-08: return 1 on error [Patrick Van der Veken] # @(#) 2018-04-30: fixes on variable names Patrick Van der Veken] # @(#) 2018-05-20: added dump_logs() [Patrick Van der Veken] +# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -37,7 +38,7 @@ function check_linux_vz_ct_status # ------------------------- CONFIGURATION starts here ------------------------- typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" typeset _VZLIST_BIN="/usr/sbin/vzlist" -typeset _VERSION="2018-05-20" # YYYY-MM-DD +typeset _VERSION="2018-05-21" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -91,8 +92,8 @@ grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | while read _CT_ENTRY do # field split _CT_ID="$(print ${_CT_ENTRY} | cut -f1 -d';')" - _CT_CFG_STATUS=$(data_lc $(print "${_CT_ENTRY}" | cut -f2 -d';')) - _CT_CFG_BOOT=$(data_lc $(print "${_CT_ENTRY}" | cut -f3 -d';')) + _CT_CFG_STATUS=$(data_lc $(print "${_CT_ENTRY}" | cut -f2 -d';' 2>/dev/null)) + _CT_CFG_BOOT=$(data_lc $(print "${_CT_ENTRY}" | cut -f3 -d';' 2>/dev/null)) # check config case "${_CT_ID}" in @@ -138,8 +139,8 @@ do if [[ -n "${_CT_MATCH}" ]] then # field split - _CT_RUN_STATUS=$(data_lc $(print "${_CT_MATCH}" | tr -s ' ' ';' | cut -f3 -d';')) - _CT_RUN_BOOT=$(data_lc $(print "${_CT_MATCH}" | tr -s ' ' ';' | cut -f4 -d';')) + _CT_RUN_STATUS=$(data_lc $(print "${_CT_MATCH}" | tr -s ' ' ';' 2>/dev/null | cut -f3 -d';' 2>/dev/null)) + _CT_RUN_BOOT=$(data_lc $(print "${_CT_MATCH}" | tr -s ' ' ';' 2>/dev/null | cut -f4 -d';' 2>/dev/null)) if [[ "${_CT_RUN_STATUS}" = "${_CT_CFG_STATUS}" ]] then diff --git a/sources/lib/platform/linux/check_linux_winbind_status.sh b/sources/lib/platform/linux/check_linux_winbind_status.sh index 7a59876..1aded84 100644 --- a/sources/lib/platform/linux/check_linux_winbind_status.sh +++ b/sources/lib/platform/linux/check_linux_winbind_status.sh @@ -25,6 +25,7 @@ # @(#) 2013-05-17: initial version [Patrick Van der Veken] # @(#) 2016-12-01: added systemd code [Patrick Van der Veken] # @(#) 2017-05-08: fix fall-back for sysv->pgrep [Patrick Van der Veken] +# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -35,7 +36,7 @@ function check_linux_winbind_status # ------------------------- CONFIGURATION starts here ------------------------- typeset _WINBIND_INIT_SCRIPT="/etc/init.d/winbind" typeset _WINBIND_SYSTEMD_SERVICE="winbind.service" -typeset _VERSION="2017-05-08" # YYYY-MM-DD +typeset _VERSION="2018-05-21" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -62,7 +63,7 @@ done linux_get_init case "${LINUX_INIT}" in 'systemd') - systemctl --quiet is-active ${_WINBIND_SYSTEMD_SERVICE} || _STC=1 + systemctl --quiet is-active ${_WINBIND_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=1 ;; 'upstart') warn "code for upstart managed systems not implemented, NOOP" @@ -71,7 +72,7 @@ case "${LINUX_INIT}" in 'sysv') if [[ -x ${_WINBIND_INIT_SCRIPT} ]] then - if (( $(${_WINBIND_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'running') == 0 )) + if (( $(${_WINBIND_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'running' 2>/dev/null) == 0 )) then _STC=1 fi @@ -88,7 +89,7 @@ esac # 2) try the pgrep way (note: old pgreps do not support '-c') if (( _RC != 0 )) then - (( $(pgrep -u root winbind 2>>${HC_STDERR_LOG} | wc -l) == 0 )) && _STC=1 + (( $(pgrep -u root winbind 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1 fi # evaluate & log results