diff --git a/check_sympa_spool_msg_dir.sh b/check_sympa_spool_msg_dir.sh index e08c5df..53af427 100755 --- a/check_sympa_spool_msg_dir.sh +++ b/check_sympa_spool_msg_dir.sh @@ -62,7 +62,7 @@ error (){ if $terminal ; then echo -e " [ \033[31m\033[1mError\033[m ]: $*" else - echo "[ Error ]: $*" + echo " [ Error ]: $*" fi echo "" } @@ -78,7 +78,7 @@ warn (){ info (){ if $terminal ; then echo "" - echo -e " [ \033[32m\033[1mInfo\033[m ] $*" + echo -e " [ \033[32m\033[1mInfo\033[m ]: $*" echo "" fi } @@ -361,7 +361,17 @@ if [[ ${#potential_critical_msg_file[@]} -lt 1 ]] ; then \033[1mAll is fine.\033[m - Script ends here." - rm -rf "${TMP_SPOOL_MSG_DIR}" + if [[ -d "${TMP_SPOOL_MSG_DIR}" ]] ; then + rm -rf "${TMP_SPOOL_MSG_DIR}" + + if ! $terminsl ; then + echo "" + echo -e " [ Info ]: No critical message(s) in folder '${SYMPA_SPOOL_MSG_DIR}' found. + + ." + echo "" + fi + fi clean_up 0 else blank_line @@ -420,6 +430,7 @@ if $terminal ; then echo "" fi +_found_file_second_time=false if ! $tmp_spool_msg_folder_exists ; then for _file in ${potential_critical_msg_file[@]} ; do echononl "Copy file \033[1m${_file}\033[m into ${TMP_SPOOL_MSG_DIR}.." @@ -433,94 +444,125 @@ if ! $tmp_spool_msg_folder_exists ; then fi done - clean_up 0 -fi - -_found_file_second_time=false -for _file in ${potential_critical_msg_file[@]} ; do - - if containsElement "$_file" "${tmp_potential_critical_msg_file[@]}" ; then - - _found_file_second_time=true - - blank_line - echononl "Remove \033[1m${_file}\033[m from directory \033[1m${SYMPA_SPOOL_MSG_DIR}\033[m.." - rm "${SYMPA_SPOOL_MSG_DIR}/${_file}" > $log_file 2>&1 - if [[ $? -lt 1 ]] ; then - echo_done - else - echo_failed - - error "$(cat $log_file)" - fi - - echononl "Remove \033[1m${_file}\033[m from directory \033[1m${TMP_SPOOL_MSG_DIR}\033[m.." - rm "${TMP_SPOOL_MSG_DIR}/${_file}" > $log_file 2>&1 - if [[ $? -lt 1 ]] ; then - echo_done - else - echo_failed - - error "$(cat $log_file)" - fi - - else - - blank_line - echononl "Copy file \033[1m${_file}\033[m into ${TMP_SPOOL_MSG_DIR}.." - cp -a "${SYMPA_SPOOL_MSG_DIR}/${_file}" "${TMP_SPOOL_MSG_DIR}/" > $log_file 2>&1 - if [[ $? -lt 1 ]] ; then - echo_done - else - echo_failed - - error "$(cat $log_file)" - fi - - fi - -done - - -# ---------- -# - Some post-script tasks .. -# ---------- - -if $terminal ; then - echo "" - echo "" - echo -e " \033[1mDoing some post-script tasks ..\033[m" - echo "" -fi - - -# If directory ${TMP_SPOOL_MSG_DIR} is empty remove it. -# -echononl "Remove directory \033[1m${TMP_SPOOL_MSG_DIR}\033[m.." -if $(is_empty_directory "${TMP_SPOOL_MSG_DIR}") ; then - - rmdir "${TMP_SPOOL_MSG_DIR}" > $log_file 2>&1 - if [[ $? -lt 1 ]] ; then - echo_done - else - echo_failed - - error "$(cat $log_file)" - fi + #clean_up 0 else - echo_skipped - warn "Directory \033[1m${TMP_SPOOL_MSG_DIR}\033[m is not empty!" + + for _file in ${potential_critical_msg_file[@]} ; do + + if containsElement "$_file" "${tmp_potential_critical_msg_file[@]}" ; then + + _found_file_second_time=true + + blank_line + echononl "Remove \033[1m${_file}\033[m from directory \033[1m${SYMPA_SPOOL_MSG_DIR}\033[m.." + rm "${SYMPA_SPOOL_MSG_DIR}/${_file}" > $log_file 2>&1 + if [[ $? -lt 1 ]] ; then + echo_done + else + echo_failed + + error "$(cat $log_file)" + fi + + echononl "Remove \033[1m${_file}\033[m from directory \033[1m${TMP_SPOOL_MSG_DIR}\033[m.." + rm "${TMP_SPOOL_MSG_DIR}/${_file}" > $log_file 2>&1 + if [[ $? -lt 1 ]] ; then + echo_done + else + echo_failed + + error "$(cat $log_file)" + fi + + else + + blank_line + echononl "Copy file \033[1m${_file}\033[m into ${TMP_SPOOL_MSG_DIR}.." + cp -a "${SYMPA_SPOOL_MSG_DIR}/${_file}" "${TMP_SPOOL_MSG_DIR}/" > $log_file 2>&1 + if [[ $? -lt 1 ]] ; then + echo_done + else + echo_failed + + error "$(cat $log_file)" + fi + + fi + + done fi -if $_found_file_second_time ; then - echononl "Try to (ee)start sympa service.." - systemctl restart sympa > $log_file 2>&1 - if [[ $? -lt 1 ]] ; then - echo_done - else - echo_failed +if ! $_found_file_second_time ; then - error "$(cat $log_file)" + if $terminal ; then + blank_line + info "Right now there is nothing more to do as the critical files have been found for the first time." + else + echo "" + echo -e " [ Info ]: Right now there is nothing more to do as the critical files have been found + for the first time." + echo "" + fi + +else + + # ---------- + # - Some post-script tasks .. + # ---------- + + if $terminal ; then + echo "" + echo "" + echo -e " \033[1mDoing some post-script tasks ..\033[m" + echo "" + else + echo "" + echo -e " [ Info ]: Critical files have been removed from the spool directory. '${SYMPA_SPOOL_MSG_DIR}'" + echo "" + fi + + + # If directory ${TMP_SPOOL_MSG_DIR} is empty remove it. + # + echononl "Remove directory \033[1m${TMP_SPOOL_MSG_DIR}\033[m.." + if $(is_empty_directory "${TMP_SPOOL_MSG_DIR}") ; then + + rmdir "${TMP_SPOOL_MSG_DIR}" > $log_file 2>&1 + if [[ $? -lt 1 ]] ; then + echo_done + + if $terminal ; then + echononl "Try to (re)start sympa service.." + else + echo "" + echo " [ Info ]: Try restarting sympa service now.." + echo "" + fi + #systemctl restart sympa > $log_file 2>&1 + if [[ $? -lt 1 ]] ; then + echo_done + else + echo_failed + + error "$(cat $log_file)" + fi + + else + echo_failed + + error "$(cat $log_file)" + fi + else + echo_skipped + + if $terminal ; then + warn "Directory \033[1m${TMP_SPOOL_MSG_DIR}\033[m is not empty!" + else + echo "" + echo " [ Warn ]: Directory '${TMP_SPOOL_MSG_DIR}' is not empty. + Now, awaiting next run of this script.." + echo "" + fi fi fi