howto to count number of files in particular d irectory on windows server?

Tom DE BLENDE (GCC) Tom.DeBlende at dhl.com
Wed Sep 15 08:51:48 CEST 2004


Using nrpe_nt is one option. I monitor the queue directory of our 
TrendMicro VirusWall servers by using smbclient and counting the temp 
files. It is easier to setup, as you don't need anything special on the 
Windows server. Here is the Bash script I'm using to do the monitoring:

<code>
#!/bin/sh
hostname=$1

if [ "$hostname" == "" ]; then
        echo -e "\nYou did not supply enough arguments. \nUsage: 
./check_vwqueue.sh <host> \n \nCheck_vwqueue.sh checks for amount of 
queued mails in the mqueue directory. \nIt was written by Tom De Blende 
in 2004. \n" && exit "-1"
fi

count=`smbclient //$hostname/intscan -U domain\\\\username%password -c 
'ls issmtpd/mqueue/*.tmp; quit' | grep -v 
NT_STATUS_OBJECT_NAME_NOT_FOUND | wc -l | sed 's/ //g'`

if [ ! "$count" -eq "4" ]; then
        files=`smbclient //$hostname/intscan -U gcc\\\\nagios%Nagi0sr0x 
-c 'ls issmtpd/mqueue/*.tmp; quit' | grep -v 
NT_STATUS_OBJECT_NAME_NOT_FOUND | grep -v added | grep -v Domain | grep 
-v NO_SUCH | grep -v blocks | wc -w`
        let "files /= 8"
        if [ "$files" -gt "100" ]; then
                exit="2" && stdio="CRITICAL - $files queued files are 
found in the Viruswall mail queue.";
        elif [ "$files" -gt "30" ]; then
                exit="1" && stdio="WARNING - $files queued files are 
found in the Viruswall mail queue.";
        else
                exit="0" && stdio="OK - $files mails were queued in the 
Viruswall mail queue.";
        fi
else
        exit="3" && stdio="Could not list directory contents."
fi

echo $stdio
exit $exit

</code>

Don't forget to change the domain, username and password. I could clean 
it up by making use of more command line arguments, but I was too lazy :-)

You can edit to your needs (and probably will, because different 
smbclient versions give different output), but it gives you the general 
idea.

Kind regards,
Tom

Tedman Eng wrote:

>using built-in win2k utilities, you can use some thing like this:
>
>dir c:\ | find "File(s)"
>
>
>or recursive version:
>
>dir c:\ /s | find "File(s)" | tail -1
>
>
>-----Original Message-----
>From: scott_yem at agilent.com [mailto:scott_yem at agilent.com]
>Sent: Tuesday, September 14, 2004 11:23 AM
>To: nagios-users at lists.sourceforge.net
>Subject: RE: [Nagios-users] howto to count number of files in particular
>directory on windows server?
>
>
>I have had a similar experience, but found a version of grep and awk that
>works on a windows system (both are Free), I just had to put them in the
>path variable or in the Windows\system32 directory and then would run some
>custom scripts with the nrpe or some other plugin as I was using another
>monitoring system at that time.  This worked well for many file system items
>that we needed to monitor.
>
>Scott Yem
>Research Computing Services
>Agilent Laboratories
>-----Original Message-----
>From: nagios-users-admin at lists.sourceforge.net
>[mailto:nagios-users-admin at lists.sourceforge.net]On Behalf Of Bolduc,
>Blair
>Sent: Tuesday, September 14, 2004 8:34 AM
>To: 'Nagios (E-mail)'
>Subject: RE: [Nagios-users] howto to count number of files in particular
>directory on windows server?
>
>
>We had this exact problem.
>We wrote a small c program (30k) that resides on the fax-server that counts
>the tif files in the fax directory and return the appropriate exit code to
>nrpe_nt.
>This requires that you have the check_nrpe plugin on your nagios server, and
>nrpe_nt installed on the windows fax-server.
>NSClient doesn't allow you to execute the exe but nrpe_nt does.
>
>If you want more info or a copy of the code let me know.
>
>Blair.
>
>
>
>-----Original Message-----
>From: Alexander Schaefer [mailto:samogonka at gmx.net]
>Sent: Tuesday, September 14, 2004 09:36
>To: nagios-users at lists.sourceforge.net
>Subject: [Nagios-users] howto to count number of files in particular
>directory on windows server?
>
>
>Hello,
>
>i am searching for possibility to count the files nuber in the particular
>directory on windows server (Win NT, w2k, win2003).
>I will trigger the nagios notification if the Fax-Server doesn't send faxes:
>unfortunatly the fax-server runs based on windows-server and sometimes the
>fax
>service hangs, without the services goes down, which will be controlled by
>NSClient The only symptom, i can recognize is the growing files numer in the
>FAX-OUT directory...
>
>Has anybody solved similar problem?
>
>Thanks for all your ideas!
>
>Alex
>
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
>Project Admins to receive an Apple iPod Mini FREE for your judgement on
>who ports your project to Linux PPC the best. Sponsored by IBM. 
>Deadline: Sept. 13. Go here: http://sf.net/ppc_contest.php
>_______________________________________________
>Nagios-users mailing list
>Nagios-users at lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/nagios-users
>::: Please include Nagios version, plugin version (-v) and OS when reporting
>any issue. 
>::: Messages without supporting info will risk being sent to /dev/null
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by: thawte's Crypto Challenge Vl
>Crack the code and win a Sony DCRHC40 MiniDV Digital Handycam
>Camcorder. More prizes in the weekly Lunch Hour Challenge.
>Sign up NOW http://ad.doubleclick.net/clk;10740251;10262165;m
>_______________________________________________
>Nagios-users mailing list
>Nagios-users at lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/nagios-users
>::: Please include Nagios version, plugin version (-v) and OS when reporting
>any issue. 
>::: Messages without supporting info will risk being sent to /dev/null
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by: thawte's Crypto Challenge Vl
>Crack the code and win a Sony DCRHC40 MiniDV Digital Handycam
>Camcorder. More prizes in the weekly Lunch Hour Challenge.
>Sign up NOW http://ad.doubleclick.net/clk;10740251;10262165;m
>_______________________________________________
>Nagios-users mailing list
>Nagios-users at lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/nagios-users
>::: Please include Nagios version, plugin version (-v) and OS when reporting
>any issue. 
>::: Messages without supporting info will risk being sent to /dev/null
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by: thawte's Crypto Challenge Vl
>Crack the code and win a Sony DCRHC40 MiniDV Digital Handycam
>Camcorder. More prizes in the weekly Lunch Hour Challenge.
>Sign up NOW http://ad.doubleclick.net/clk;10740251;10262165;m
>_______________________________________________
>Nagios-users mailing list
>Nagios-users at lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/nagios-users
>::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
>::: Messages without supporting info will risk being sent to /dev/null
>
>  
>



-------------------------------------------------------
This SF.Net email is sponsored by: thawte's Crypto Challenge Vl
Crack the code and win a Sony DCRHC40 MiniDV Digital Handycam
Camcorder. More prizes in the weekly Lunch Hour Challenge.
Sign up NOW http://ad.doubleclick.net/clk;10740251;10262165;m
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list