Home Directory Plugins Operating Systems Linux check_dir_filecount.sh

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

check_dir_filecount.sh

Rating
2 votes
Favoured:
0
Hits
148876
Files:
FileDescription
check_dir_filecount.shThe plugin.

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

Nagios plugin to check number of files in a directory. Written in bash, intended to be used on Linux systems.
Nagios plugin to check number of files in a directory. Written in bash, intended to be used on Linux systems. I've only tested with Nagios 3.0.2, but it should work with v2 as well. Usage is "check_dir_filecount.sh [directory] [warn value] [critical value]".
Reviews (1)
byxoroz, April 6, 2011
Had errors running the script.
I modified it for

#!/bin/bash

# Return codes:

STATE_OK=0

STATE_WARNING=1

STATE_CRITICAL=2

STATE_UNKNOWN=3

# Arguments:

DIRECTORY=$1

WARNLEVEL=$2

CRITLEVEL=$3

# Get current file count:

FCOUNT=`ls -l $DIRECTORY |grep -v tot* |wc -l`

#echo "Total files in $DIRECTORY is $FCOUNT"

if [ $FCOUNT -lt $WARNLEVEL ]; then

echo "OK, $FCOUNT items in $DIRECTORY|files=$FCOUNT"

exitstatus=$STATE_OK

exit $exitstatus
fi
if [ $FCOUNT -gt $CRITLEVEL ]; then

echo "CRITICAL: $FCOUNT items in $DIRECTORY|files=$FCOUNT"

exitstatus=$STATE_CRITICAL

exit $exitstatus
fi
if [ $FCOUNT -gt $WARNLEVEL ]; then

echo "WARNING: $FCOUNT items in $DIRECTORY|files=$FCOUNT"

exitstatus=$STATE_WARNING

exit $exitstatus
fi


and it works fine