%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/thread-self/root/proc/self/root/lib64/nagios/plugins/nccustom/
Upload File :
Create Path :
Current File : //proc/thread-self/root/proc/self/root/lib64/nagios/plugins/nccustom/check-cpanel-update.sh

#!/bin/bash

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

resultFile="/var/log/nc_audit/check_sec_updates"
agetreshold=16 # 16 hours

#input option

PROGNAME=${0##*/}

print_usage() {
    echo ""
    echo "Usage: $PROGNAME [-f Diff path] [-a file Age treshold, hours]"
    echo "Usage: $PROGNAME -h | --help"
}

print_help() {
    print_usage
    echo ""
    echo "This script check cPanel security updates (see TOP-347)"
    echo ""
    echo "-f Different path and file. Default - /var/log/nc_audit/check_sec_updates"
    echo "-a Age treshold for logfiles, hours. Default - 16"
    echo "-h help Print this help screen"
    echo "--help Print this help screen"
    echo ""
    exit 3
}

while [ $# -gt 0 ]; do

    case "$1" in
        -f)
         resultFile=$2; shift
         ;;

        -a)
        agetreshold=$2; shift
        ;;

        --help)
        print_help
        exit 3
         ;;

        -h)
        print_help
        exit 3
         ;;

        *)
        echo >&2 "Unknown argument: $1"
        print_usage
        exit 3
        ;;

        esac
        shift
done

#file existence

if [ ! -f "$resultFile" ]; then
    echo "UNKNOWN. $resultFile no file"
    exit 3
fi

#check age file

resultFileAge=$((($(date +%s) - $(date +%s -r "${resultFile}")) / 3600))    # in hours

if (( resultFileAge > agetreshold )) ; then
    echo "UNKNOWN. File ${resultFile} older than ${agetreshold} hours"
    exit 3
fi

#checking file status

read -r firstline<"$resultFile"

firstline_code=$(echo "${firstline}" | awk '{print$1}' | sed 's/\[\|\]://g')

case "${firstline_code}" in

    "OK" )
    exitcode="0"
    ;;

    "FAILED" | "CRITICAL" )
    exitcode="2"
    ;;

    * )                         #Unknown state
    firstline="UNKNOWN. String from $resultFile does not match any pattern"
    exitcode="3"
    ;;

esac

echo "$firstline"
exit "$exitcode"

Zerion Mini Shell 1.0