michabbb of BS Webtool
2/23/2016 - 5:44 PM

Nagios Check File exists last x days

Nagios Check File exists last x days

# Felix Schabmeyer 23.02.2016
# check_file_exists_last_days
# Nagios check which checks for x days if there is a specified or wildcarded file available in a specified folder
#! /bin/bash

FILE=`find $2 -mtime -$1 -type f -name "$3" | sort -r | head -n 1`

if [ "$1" = "" ] || [ "$2" = "" ] || [ "$3" = "" ]
then
  echo -e " Use : check_file_exists_last_days <last x days> <folder> <file_name> -- Ex : check_file_exists_last_days /backup/ "*.bz2" \n "
  exit 2
fi
  
  
if [ ! $FILE ]
then
  echo "CRITICAL - $1 : NOT EXISTS"
  exit 2
else
  echo "OK : $1 EXISTS"
  echo "newest File: $FILE" #SHOW NEWEST FILE
  exit 0
fi