Last active
January 30, 2018 21:25
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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