Skip to content
Snippets Groups Projects
check_fs_errors 2.34 KiB
#!/usr/bin/env bash
# ======================================================================
#
# Check filesystem errors
#
#
# requirements:
# - sudo permission on /bin/journalctl
#
# ----------------------------------------------------------------------
# 2021-03-23  v1.0  <axel.hahn@iml.unibe.ch>
# 2021-03-30  v1.1  <axel.hahn@iml.unibe.ch>  max age of detected errors: since yesterday (commented)
# 2023-07-27  v1.2  <axel.hahn@unibe.ch>      shell fixes; update help page
# 2023-10-20  v1.3  <axel.hahn@unibe.ch>      harden sudo command execution
# 2025-02-10  v1.4  <axel.hahn@unibe.ch>      harden sourcing files
# ======================================================================

# shellcheck source=/dev/null
. "$( dirname "$0" )/inc_pluginfunctions" || exit 1

export self_APPVERSION=1.4


# ----------------------------------------------------------------------
# functions
# ----------------------------------------------------------------------

function showHelp(){
    local _self; _self=$(basename $0)
    cat <<EOF
$( ph.showImlHelpHeader )

Check if kernel logs inconsistency messages in the journallog.
It requires sudo permission on /bin/journalctl

SYNTAX:
$_self [-h]

OPTIONS:

    -h or --help   show this help.

PARAMETERS:

    none

EXAMPLE:
$_self

EOF
}
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------

# --- check required tools
ph.require journalctl


# --- check param -h
case "$1" in
    "--help"|"-h")
        showHelp
        exit 0
        ;;
    *)
esac


# ----- MAKE CHECK

if ! sudo -n journalctl --since today -k -n 1 2>&1 >/dev/null ; then
    ph.abort "UNKNOWN: No sudo permissions to execute journalctl."
fi
# sincedate=$( date +%Y-%m-%d --date 'yesterday' )
# out=$( sudo /bin/journalctl --since $sincedate | grep 'kernel: ' | grep -v 'check_fs_errors' | grep -E '(error|fail)' | grep 'inconsistent' )
out=$( sudo -n /bin/journalctl -k --since yesterday | grep 'kernel: ' | grep -v 'check_fs_errors' | grep -E '(error|fail)' | grep 'inconsistent' )

# ----- OUTPUT

if [ -n "$out" ]; then
    ph.setStatus "critical"
    ph.status "kernel logs show inconsistency messages (since yesteray)"
    echo "$out"
else
    ph.status "No inconsistency messages"
fi

ph.exit

# ----------------------------------------------------------------------