#!/bin/bash STATE_OK=0 STATE_WARNING=1 STATE_CRITICAL=2 STATE_UNKNOWN=3 run_command="$1" hours="$2" as_user="$3" if [ -z "$as_user" ]; then last_date=$($run_command 2>/dev/null | sort | tail -n 1) else last_date=$(sudo -u "$as_user" $run_command 2>/dev/null | sort | tail -n 1) fi if [ -z "$last_date" ]; then echo "UNKNOWN: Could not read date" exit $STATE_UNKNOWN else last_date=$(date -d "$last_date" "+%s") LC_ALL=C last_date=$(printf "%.*f" 0 $last_date) min_date=$(date -d "$hours hours ago" "+%s") if [ "$min_date" -lt "$last_date" ]; then echo "OK: Last date $(date -d @$last_date)" exit $STATE_OK else echo "CRITICAL: Last date $(date -d @$last_date)" exit $STATE_CRITICAL fi fi