/usr/lib/mon-contrib/mon.d/smblist.monitor is in mon-contrib 1.0+dfsg-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | #!/usr/bin/perl -w
#
# run "smbclient -N -L host" or "smbclient //host/ password -U username -L host"
# on a bunch of hosts. For use with "mon".
#
# Arguments are "host [-u username -p password] [host...]"
#
# The password is public property! It should not be a valuable one.
#
# Copyright (C) 2001, Matthew Astley <mca-gdl@users.sourceforge.net>
# Hacked from Jim Trocki's tcp.monitor
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
use strict;
my %failures = ();
my $TIMEOUT = 20;
my $ALARM = 0;
my ($user, $pass);
if ( $ARGV[0] eq '-u' && $ARGV[2] eq '-p' ) {
$user = $ARGV[1];
$pass = $ARGV[3];
splice @ARGV, 0, 4;
}
foreach my $host (@ARGV) {
my ($txt, $ret);
my $credentials = (defined $user ? "$pass -U $user" : "-N");
my $cmd = "smbclient //$host/ $credentials -L $host";
eval {
local $SIG{"ALRM"} = sub { die "alarm\n" };
alarm $TIMEOUT;
$txt = `$cmd 2>&1`;
$ret = $?;
alarm 0;
};
if ($@) {
$failures{$host} =
($@ eq "alarm\n" ? "timeout" : "unknown error $@");
next;
}
if ($ret != 0) {
$failures{$host} = sprintf("> %s\nReturncode 0x%X\n", $cmd, $ret);
$failures{$host} .= $txt if defined $txt;
next;
}
# If we gave a username, then we don't expect to be refused the shares list
# (some servers give the share list anyway, but Win2k upwards seem to require a valid user)
if ( ($txt =~ /Error returning browse list/ ||
$txt =~ /NT_STATUS_ACCESS_DENIED/ ) &&
defined $user )
{
$failures{$host} = "> $cmd\n$txt"; # maybe a little too verbose
}
}
exit 0 unless scalar %failures;
print join " ", sort keys %failures;
print "\n\n", join ("\n", map { ">> $_\n$failures{$_}" } sort keys %failures), "\n";
exit 1;
|