check for filesize on windows using nrpe
Stanley Hopcroft
Stanley.Hopcroft at IPAustralia.Gov.AU
Fri Feb 7 13:22:59 CET 2003
Dear Sir,
I am writing to thank you for your letter and say,
On Fri, Feb 07, 2003 at 10:07:35AM +0000, Horst Thiveßen wrote:
> Hello,
> I have to check the filesize on a windows 2000 server. I am not firm with
> progamming on windows and therefor I am looking for a nrpe agent which I
> can apapt with little knowledge of perl. Has anybody such a plugin ?
that you may like to consider the CPAN module FileSys::Smbclient ?
This gives you an (tied) interface to a MS shared file that behaves
exactly like a normal (ufs) file handle, so you can call stat() on it.
I think your plugin is something like
.. prelude
my $smb = new Filesys::SmbClient(username => "alian",
password => "speed",
workgroup => "alian",
debug => 10);
my @tab = $smb->stat("smb://jupiter/doc/tata");
if ($#tab == 0) { print "Erreur in stat:", $!, "\n";
# Outahere after setting return code
}
else {
my $size = $tab[7];
if ( $size <= MIN_THRESHOLD or $size >= MAX_THRESHOLD ) {
# outahere
} else
# Ok
print "File Ok.\n" ;
exit $ERRORS{OK} ;
}
Have a look at
http://search.cpan.org/author/ALIAN/Filesys-SmbClient-1.4/SmbClient.pm
Obviously you can do a lot more with this extremely versatile and
superior alternative to smbclient eg
- tail a MS file
- read/write at offset
- slurp a whole MS file into a Perl string or Array
- read/write MS directories
You need to have a Samba 2.2.x sources, and you need to have the
optional client shared library installed (make installclientlib) to be
able to install this Perl module.
Alternatively, there are RPMs that are sufficient to do all this.
If you don't like this, but you have Samba installed, then
you could do something like
#!/usr/bin/perl
$ls = `smbclient //server/share -Uuser%pass -c 'cd $path; ls
$file; quit`` ;
# interpret the directory listing in the 'usual way' ... this is
# the hard bit that FileSys::Smbclient eliminates.
> Thanks Horst
HTH,
Yours sincerely.
--
------------------------------------------------------------------------
Stanley Hopcroft
------------------------------------------------------------------------
'...No man is an island, entire of itself; every man is a piece of the
continent, a part of the main. If a clod be washed away by the sea,
Europe is the less, as well as if a promontory were, as well as if a
manor of thy friend's or of thine own were. Any man's death diminishes
me, because I am involved in mankind; and therefore never send to know
for whom the bell tolls; it tolls for thee...'
from Meditation 17, J Donne.
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
More information about the Users
mailing list