Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

CheckFileCount

Rating
2 votes
Favoured:
0
Hits
148667
Files:
FileDescription
check_numoffiles.shcheck_numoffiles.sh

Help Support Ethan Galstad's New Project:

Help Support Ethan

A Message From The Founder...

As the founder of Nagios, I'm asking for your help in a cause that's dear to my heart.

I'm launching a new project to help better the world by providing the information, ideas, and inspiration that I believe can improve the lives of people everywhere.

I know you're busy managing networks, but I would appreciate it if you would consider liking my Facebook page and showing your support for the content and messages I produce by sharing them with your friends and family.

You can learn more about my project by visiting ethangalstad.me/nagios. Thank you for your time. I wish you all the best in your endeavors, whatever they may be.

- Ethan

Monitor file count of a directory and notify if the count of files exceedes threshold. Shell script (sh), GPL
## Description

This plugin determines the file count of a directory (without sub dirs) and compares it with the supplied thresholds.

Usage: check_numoffiles -d path -w warn -c crit

## Output:

The plugin prints the count of files in the directory followed by "ok" or either "warning" or "critical" if the corresponing threshold is reached.

Exit Codes
0 = OK (Directory count of files checked and everything is ok)
1 = Warning (Directory count of files above "warning" threshold)
2 = Critical (Directory count of files above "critical" threshold)
3 = Unknown (Invalid command line arguments or could not determine directory size)

## Example

check_numoffiles -d . -w 1000 -c 1400

121 files - ok (exit code 0)
1234 files - warning (exit code 1)
1633 files - critical (exit code 2)
Reviews (1)
It works but I needed to make some enhancements.
Not sure how updates on NagiosExchange works so I'll mention them here.

Removed dependacy on /usr/bin/basename

PROGNAME=$0
PROGPATH=${PROGNAME%/*}
PROGNAME=${PROGNAME##*/}

Replaced -ge by -gt to allow warning/error for 0 files on directories that should be empty.