-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetDrives.pl
More file actions
164 lines (147 loc) · 3.9 KB
/
getDrives.pl
File metadata and controls
164 lines (147 loc) · 3.9 KB
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
#!/usr/bin/perl -w
#
#
# Copyright (C) 2013 Dominik Sigmund
#
# 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;
use Getopt::Long;
use vars qw($PROGNAME);
use vars qw($VERSION);
my ( $opt_V, $opt_h, $opt_t, $opt_m, $opt_f, $cmd, $output);
$PROGNAME = "getDrives.pl";
$VERSION = "0.5";
sub print_usage () {
print "Short syntax summary: \n";
print "getDrives.pl -t /var/www/ \n\n";
print "getDrives.pl -t /var/www/ -f xml -m Videos\n\n";
}
sub print_help () {
print "Copyright (c) 2013 Dominik Sigmund";
print_usage();
print "\n";
print " This output\n";
print "\n";
}
# Perl trim function to remove whitespace from the start and end of the string
sub trim($)
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}
Getopt::Long::Configure('bundling');
GetOptions(
"V" => \$opt_V,
"version" => \$opt_V,
"h" => \$opt_h,
"help" => \$opt_h,
"t=s" => \$opt_t,
"target" => \$opt_t,
"f=s" => \$opt_f,
"format" => \$opt_f,
"m=s" => \$opt_m,
"mount" => \$opt_m
);
if ($opt_V) {
print $VERSION;
exit 0;
}
if ($opt_h) {
print_help();
exit 0;
}
if ( !$opt_t ) {
print "No target for HTML specified\n\n";
print_usage();
exit 3;
}
if ( !$opt_m ) {
$opt_m="a";
}
if ( !$opt_f ) {
$opt_f="html";
}
# Step 0: Perform Command
if($opt_m eq "a"){
open (DF, "df -h|") or die "$!\n";
}
else {
open (DF, "df -h| grep ".$opt_m ."|") or die "$!\n";
}
# Step 1: und ausgeben
$output ="<html>";
$output .= "<head>";
$output .= " <title>Drives</title>";
$output .= " <style>";
$output .= " #progress {
width: 500px;
border: 1px solid black;
position: relative;
padding: 3px;
}
#percent {
position: absolute;
left: 50%;
}
#bar {
height: 20px;
}";
$output .= " </style>";
$output .= "</head>";
$output .= "<body>";
$output .= "<table border=1>\n";
$output .= "<tr><th colspan=\"6\">Daten</th></tr>\n";
$output .= "<tr><th>Dateisystem</th><th>Größe</th><th>Belegt</th><th>Verfügbar</th><th>Bel %</th><th>Belegt</th></tr>\n";
while (<DF>) {
if($opt_m eq "a"){
next if $. == 1;
}
my @values = split(/ {1,}/, $_);
$output .= "<tr>";
$output .= "<td>".$values[0]."</td>";
$output .= "<td>".$values[1]."</td>";
$output .= "<td>".$values[2]."</td>";
$output .= "<td>".$values[3]."</td>";
$output .= "<td>".$values[4]."</td>";
$output .= "<td><div id=\"progress\">";
$output .= " <span id=\"percent\">".$values[4]."</span>";
my $val_flat = $values[4];
$val_flat =~ s/%//g;
my $bg="green";
if($val_flat lt 50){
$bg="green";
}
elsif($val_flat lt 90 && $val_flat gt 50){
$bg="orange";
}
else {
$bg="red";
}
$output .= " <div id=\"bar\" style=\"width:".$values[4].";background-color: ".$bg.";\"></div>";
$output .= "</div></td>";
$output .= "</tr>\n";
}
$output .= "</table>\n";
$output .= "</body>";
$output .= "</html>";
close(DF);
open (OUTPUT, '>'.$opt_t.'drives.html');
print OUTPUT $output;
close (OUTPUT);
exit 0;