This file is indexed.

/usr/share/logwatch/scripts/services/zz-disk_space is in logwatch 7.4.1-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
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/perl
#######################################################
## Copyright (c) 2008 Kirk Bauer
## Covered under the included MIT/X-Consortium License:
##    http://www.opensource.org/licenses/mit-license.php
## All modifications and contributions by other persons to
## this script are assumed to have been donated to the
## Logwatch project and thus assume the above copyright
## and licensing terms.  If you want to make contributions
## under your own copyright or a different license this
## must be explicitly stated in the contribution an the
## Logwatch project reserves the right to not accept such
## contributions.  If you have made significant
## contributions to this script and want to claim
## copyright please contact logwatch-devel@lists.sourceforge.net.
#########################################################

$| = 1;

use POSIX qw(uname);

my (%Config);

my $Debug = $ENV{'LOGWATCH_DEBUG'} || 0;
my $Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'} || 0;
my $logwatch_hostname = $ENV{'LOGWATCH_ONLY_HOSTNAME'};

my $show_home_dir_sizes = $ENV{'show_home_dir_sizes'} || 0;
my $home_dir = $ENV{'home_dir'} || 0;
my $show_mail_dir_sizes = $ENV{'show_mail_dir_sizes'} || 0;
my $mail_dir = $ENV{'mail_dir'} || 0;
my $show_disk_usage = $ENV{'show_disk_usage'} || 0;
my $diskfull_threshhold = $ENV{'diskfull_threshold'} || 90;
my $local_disks_only = $ENV{'local_disks_only'} || 0;

my $df_options;
my $disk_cmd;

my ($OSname, $hostname, $release, $version, $machine) = POSIX::uname();
$hostname =~ s/\..*//;
exit (0) if ($ENV{'LOGWATCH_ONLY_HOSTNAME'} and ($logwatch_hostname ne $hostname));

if ( $Debug >= 5 ) {
	print STDERR "\n\nDEBUG: Inside zz-disk-space Filter \n\n";
	$DebugCounter = 1;
}

sub DirUsage {
	my $Dir = $_[0];
	if ($OSname eq "Linux") {
		system("du -s --block-size=1048576 -h $Dir | sort -n -r -k 1");
	} elsif ($OSname eq "Darwin") {
		system("du -s --block-size=1048576 -h $Dir | sort -n -r -k 1");
	} elsif ($OSname eq "SunOS") {
		if ( ($release eq "5.10") || ($release eq "5.9") || ($release eq "5.11") ) {
		   system("/usr/xpg4/bin/du -s -h $Dir | sort -n -r -k 1");
      } else {
         system("du -s $Dir | sort -n -r -k 1");
      }
	} elsif ($OSname eq "HP-UX") {
		system("du -s -k $Dir | sort -n -r -k 1");
	} elsif ($OSname eq "AIX") {
	 	system("du -s -k $Dir | sort -n -r -k 1");
	} else {
	  	system("du -s -h $Dir | sort -n -r -k 1");
	}
}

sub DirectorySizes
{
	my $Dir = $_[0];
	DirUsage($Dir.'/*');
}

sub HomeDirectorySizes
{
	my $HomeDir = $_[0];
	print "\n\n------------- Home Directory Sizes ---------------\n\n";
	print "Size    Location\n";
	DirectorySizes($HomeDir);
	print "\n\n------------- Home Directory Sizes ---------------\n\n";
}

sub MailDirectorySizes
{
	my $MailDir = $_[0];
	print "\n\n------------- Mail Directory Sizes ---------------\n\n";
	print "Size    Location\n";
	DirectorySizes($MailDir);
	print "\n\n------------- Mail Directory Sizes ---------------\n\n";
}

sub DiskUsage ()
{
	my $Dir = $_[0];
	print "\n\n------------- Directory Sizes ---------------\n\n";
	print "Size    Location\n";

	if ($OSname eq "Linux") {
	 	DirUsage("/var/log");
	 	DirUsage("/usr");
	} elsif ($OSname eq "Darwin") {
		DirUsage("/var/log");
		DirUsage("/usr");
	} elsif ($OSname eq "SunOS") {
		DirUsage("/var/log");
		DirUsage("/usr");
		DirUsage("/opt");
	} elsif ($OSname eq "HP-UX") {
		DirUsage("/var/adm");
		DirUsage("/usr");
		DirUsage("/opt");
	} else {
		DirUsage("/var/log");
		DirUsage("/usr");
		DirUsage("/opt");
	}

	print "\n\n------------- Directory Sizes ---------------\n\n";

}

sub DiskSpace ()
{
	if ($OSname eq "Linux") {
		$df_options = "-h -x tmpfs -x udf -x iso9660";
		if ($local_disks_only) { $df_options .= " -l"; }
	} elsif ($OSname eq "Darwin") {
		$df_options = "-h";
		if ($local_disks_only) { $df_options .= " -l"; }
	} elsif ($OSname eq "SunOS") {
		if ( ($release eq "5.10") || ($release eq "5.9") || ($release eq "5.11") ) {
			$df_options = "-h";
		} 
		if ($local_disks_only) { $df_options .= " -l"; }
	} elsif ($OSname eq "HP-UX") {
		$df_options = "";
		if ($local_disks_only) { $df_options .= " -l"; }
	} elsif ($OSname eq "AIX") {
		$df_options = "";
		if ($local_disks_only) { $df_options .= " -P"; }
	} elsif ($OSname eq "GNU/kFreeBSD") {
		$df_options = "-h -x tmpfs -x udf -x iso9660 -x devfs -x linprocfs -x sysfs -x fdescfs";
		if ($local_disks_only) { $df_options .= " -l"; }
	} else {
		$df_options = "";
		if ($local_disks_only) { $df_options .= " -l"; }
	}

	if ( $ENV{'df_options'} ) {
		$df_options = $ENV{'df_options'};
	};

	if ($OSname eq "Linux") {
		$disk_cmd = "df $df_options";
	} elsif ($OSname eq "Darwin") {
		$disk_cmd = "df $df_options";
	} elsif ($OSname eq "SunOS") {
		$disk_cmd = "/usr/xpg4/bin/df $df_options";
	} elsif ($OSname eq "HP-UX") {
		$disk_cmd = "bdf $df_options";
	} else {
		$disk_cmd = "df $df_options";
	}

	if ( $ENV{'disk_cmd'} ) {
		$disk_cmd = $ENV{'disk_cmd'};
	};

	system($disk_cmd);

	print "\n";
}

sub DiskFull {
	my $o = `$disk_cmd`;
	my @rows = split('\n', $o);
	foreach my $row (@rows) {
		my @fields = split(' ', $row);
		my $use = $fields[4];
		$use =~ s/%//;
		if (($use > $diskfull_threshhold) && ($fields[0] !~ /\/dev\/scd/ ) && ($fields[0] !~ /\/dev\/sr/ )
				&& ($fields[0] !~ /\/dev\/loop./)) {
			print "$fields[0] => $fields[4] Used. Warning. Disk Filling up.\n";
		}
	}
}

#####################
#Main

#Only show disk space "df" by default -mgt
DiskSpace() if (($ENV{PRINTING} eq 'y') or $Detail);

if ( $show_disk_usage == 1 ) { DiskUsage(); }; #Turn on in zz-disk_space.conf

if (($Detail > 10) || ($show_home_dir_sizes == 1)) { #set in zz-disk_space.conf -mgt
	HomeDirectorySizes($home_dir);
}

if (($Detail > 10) || ($show_mail_dir_sizes == 1)) { #set in zz-disk_space.conf -mgt
	MailDirectorySizes($mail_dir);
}

if ($diskfull_threshhold > 0) {
	DiskFull();
}

# vi: shiftwidth=3 tabstop=3 syntax=perl et
# Local Variables:
# mode: perl
# perl-indent-level: 3
# indent-tabs-mode: nil
# End: