help-cfengine
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Number of files in a directory?


From: Tim Nelson
Subject: Re: Number of files in a directory?
Date: Fri, 11 Mar 2005 10:58:05 +1100 (EST)

On Thu, 10 Mar 2005, Adams, Russell L. wrote:

Only to use:

/usr/bin/test `find /var/spool/mqueue -type f -name 'q*' | wc -l` -ge 12

instead of ls and grep and expr. ;]

Russell

On Thu, Mar 10, 2005 at 03:49:10PM -0500, nathan r. hruby wrote:
Hi,

Here's something that I'm sure someone else has solved..

I'd like to monitor the number of files in /var/spool/mqueue and do 3
things when it hits a threshold:
- Fire off a warning
- run sendmail -q
- Run a shell command to nuke some things (like SPAM!)

So,  here's what I have now, which seems fairly inelegant:
----BEGIN SNIP
classes:
        # See if we're overlimt
        MailqueOverLimit = ( ReturnsZero(/bin/sh -c "expr `ls
        /var/spool/mqueue/ | grep q.*| wc -l`  \> 12 > /dev/null") )

Couldn't you use the control section to set a variable to the number of whatevers (files), and then set the class based on that? It'd also allow you to use the variable in the alerts to say how many there are.


alerts:
        # Tell us if we're overlimit (it'd be nice to have the actual
        # number...)
        MailqueOverLimit::
                "WARNING: Mail queue is overlimit on $(fqhost)" ifelapsed=60

shellcommands:
        # Do something to make us not overlimit
        MailqueOverLimit::
                "$(nuke_spam_bounces)"
                "$(run_a_qrunner)"
----END SNIP

This seems kinda like a kludge.  Anyone have any better suggestions for
monitoring the number of files in a directory?

Hmm. If I were doing it, I'd make a shell script. Of course, that would mean that alerts wouldn't work. I might also try a cfengine method.

--
Tim Nelson
Server Administrator
WebAlive Technologies Global
Level 1 Innovation Building, Digital Harbour
1010 LaTrobe Street
Docklands, Melbourne, Vic, 3008
Phone: +61 3 9934 0812
Fax: +61 3 9934 0899
E-mail: tim.nelson@webalive.biz
http://www.webalive.biz/

"Your Business, Your Web, Your Control"




reply via email to

[Prev in Thread] Current Thread [Next in Thread]