Skip to content

Instantly share code, notes, and snippets.

@whereisaaron
Last active January 30, 2018 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whereisaaron/8a99dc33f3bd7b8d4b188393e5dafc9b to your computer and use it in GitHub Desktop.
Save whereisaaron/8a99dc33f3bd7b8d4b188393e5dafc9b to your computer and use it in GitHub Desktop.
Nagios monitoring plug-in wrapper to use check_file_age to check the newest file matching a pattern
#!/bin/bash
#
# Check the age and size of the latest file in a particular directory matching a pattern
# e.g.
# check_download_age /the/path/to/the/directory/ 'FILE_NAME_OR_GLOB*' -c 86400 -w 43200 -C 0 -W 10000
#
cfa=/usr/lib/nagios/plugins/check_file_age
: ${1?"Must supply path"}
: ${2?"Must supply file name"}
path=${1}; shift
file_pattern=${1}; shift
file_name=$(find $path -type f -name $file_pattern -exec stat --format '%Y %n' "{}" \; | sort -nr | head -1 | cut -d' ' -f2-)
if [[ "${file_name}" != "" ]]; then
$cfa -f "${file_name}" $*
else
echo "FILE_AGE CRITICAL: No matching file found"
exit 2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment