check_file_not_exists_or_younger_timeperiod
# Felix Schabmeyer 23.02.2016
# check_file_not_exists_or_younger_timeperiod
# Nagios check which checks for x minutes / days if there is a specified or wildcarded file not exists or ist younger than in a specified folder
#! /bin/bash
if [ "$1" = "" ] || [ "$2" = "" ] || [ "$3" = "" ] || [ "$4" = "" ]
then
echo -e " Use : check_file_not_exists_or_younger_timeperiod <time period: m=minutes d=days> <last x minutes/days> <folder> <file_name> -- Example : check_file_exists_or_younger_timeperiod m /backup/ "*.bz2" \n "
exit 2
fi
if [ $1 = m ]
then
TIMEPERIOD=mmin
elif [ $1 = d ]
then
TIMEPERIOD=mtime
else
echo "No proper time period was selected"
exit 2
fi
FILE=`find $3 -$TIMEPERIOD +$2 -type f -name "$4" | sort -r | head -n 1`
if [ ! $FILE ]
then
echo "OK - $3/$4 NOT EXISTS OR IS YOUNGER THAN $2$1"
exit 0
else
echo "CRITICAL : EXISTS AND IS OLDER THAN $2$1"
echo "File: $FILE" #SHOW NEWEST FILE
exi