All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
3 # Adapted from Eridan's "fs" (cleanup, enhancements and switch to bash/Linux)
6 # Integrated into Lain in september 2013
7 # https://github.com/copycat-killer/lain
11 # -------------------------------------------------------------------------
13 # -------------------------------------------------------------------------
14 USAGE="Usage: $0 [-h(elp)] | [-n(arrow mode)] | [-w(eb output)]"
19 while [ $# -gt 0 ]; do
42 # -------------------------------------------------------------------------
44 # -------------------------------------------------------------------------
50 DF_COMMAND="/usr/bin/env df -k"
51 SORT_COMMAND="/usr/bin/env sort -k6"
52 AWK_COMMAND="/usr/bin/env awk"
55 DF_COMMAND="/bin/df -k"
56 SORT_COMMAND="/usr/bin/sort -k6"
57 AWK_COMMAND="/usr/bin/env gawk"
61 # -------------------------------------------------------------------------
62 # Grabbing "df" result
63 # -------------------------------------------------------------------------
64 DF_RESULT=`$DF_COMMAND`
65 if [ ! -z $DEBUG ]; then
71 # -------------------------------------------------------------------------
72 # Preprocessing "df" result, to join split logical lines
73 # -------------------------------------------------------------------------
74 PREPROCESSING_RESULT=` \
75 echo "$DF_RESULT" | $AWK_COMMAND -v PATTERN=$PATTERN \
92 if [ ! -z $DEBUG ]; then
93 echo "--> PREPROCESSING_RESULT:"
94 echo "$PREPROCESSING_RESULT"
98 SORTED_FILE_SYSTEMS_INFO=`echo "$PREPROCESSING_RESULT" | $SORT_COMMAND`
100 if [ ! -z $DEBUG ]; then
101 echo "--> SORTED_FILE_SYSTEMS_INFO:"
102 echo "$SORTED_FILE_SYSTEMS_INFO"
106 # -------------------------------------------------------------------------
107 # Computing mount point max length
108 # -------------------------------------------------------------------------
109 MOUNT_POINT_MAX_LENGTH=` \
110 echo $SORTED_FILE_SYSTEMS_INFO | $AWK_COMMAND -v PATTERN=$PATTERN \
113 mount_point_length_max = 15;
117 printf ("%d", mount_point_length_max);
121 # printf ("$6 = %s\n", $6);
124 # printf ("mount_point = %s\n", mount_point);
126 mount_point_length = length (mount_point);
127 # printf ("mount_point_length = %d\n", mount_point_length);
129 if (mount_point_length > mount_point_length_max)
130 mount_point_length_max = mount_point_length;
133 if [ ! -z $DEBUG ]; then
134 echo "MOUNT_POINT_MAX_LENGTH: $MOUNT_POINT_MAX_LENGTH"
137 # -------------------------------------------------------------------------
138 # Computing mount point data max size
139 # -------------------------------------------------------------------------
140 MOUNT_POINT_MAX_SIZE=` \
141 echo "$SORTED_FILE_SYSTEMS_INFO" | $AWK_COMMAND -v PATTERN=$PATTERN \
144 mount_point_size_max = 0;
148 printf ("%d", mount_point_size_max);
152 # df -k shows k_bytes!
153 # printf ("$2 = %s\n", $2);
155 mount_point_size = $2 * 1024;
156 # printf ("mount_point_size = %d\n", mount_point_size);
158 if (mount_point_size > mount_point_size_max)
159 mount_point_size_max = mount_point_size;
162 if [ ! -z $DEBUG ]; then
163 echo "MOUNT_POINT_MAX_SIZE: $MOUNT_POINT_MAX_SIZE"
166 # -------------------------------------------------------------------------
168 # -------------------------------------------------------------------------
169 echo "$SORTED_FILE_SYSTEMS_INFO" | $AWK_COMMAND -v DEBUG=$DEBUG -v PATTERN=$PATTERN -v NARROW_MODE=$NARROW_MODE -v LEFT_COLUMN=$MOUNT_POINT_MAX_LENGTH -v MAX_SIZE=$MOUNT_POINT_MAX_SIZE -v SCALE=$SCALE -v WEB_OUTPUT=$WEB_OUTPUT \
171 # {printf ("$0 = %s\n", $0);}
172 # {printf ("$1 = %s\n", $1);}
173 # {printf ("PATTERN = %s\n", PATTERN);}
174 # {printf ("LEFT_COLUMN = %s\n", LEFT_COLUMN);}
178 m_bytes = 1024.0 * k_bytes;
179 g_bytes = 1024.0 * m_bytes;
180 t_bytes = 1024.0 * g_bytes;
184 all_stars = "**************************************************";
185 current_date = strftime ("%d-%m-%Y @ %H:%M:%S", localtime (systime ()));
186 free_threshold = 10; # %
188 printf ("<!-- DEBUT CONTENU -->\n");
191 "<A NAME=\"top\"></A>\n" \
192 "<P ALIGN=CENTER><SPAN CLASS=\"titleblue\">%s</SPAN><SPAN CLASS=\"textbold\"> -- STATUS OF <SPAN CLASS=\"titlered\">ALCOR</SPAN> FILE SYSTEMS</SPAN></P><BR>\n",
195 printf ("<TABLE WIDTH=\"100%%\" BORDER=1>\n");
199 "<TD ALIGN=LEFT><STRONG>Mount point</STRONG></TD>\n" \
200 "<TD ALIGN=CENTER><STRONG>%% Usato (<SPAN CLASS=\"titleblue\">*</SPAN>)" \
201 " - %% Free (<SPAN CLASS=\"titlegreen\">*</SPAN>)</STRONG></TD>\n" \
202 "<TD ALIGN=CENTER><STRONG>%% Used</STRONG></TD>\n" \
203 "<TD ALIGN=CENTER><STRONG>Free</STRONG></TD>\n" \
204 "<TD ALIGN=CENTER><STRONG>Total</STRONG></TD>\n" \
210 # printf ("%-*s", LEFT_COLUMN + 2, "Mount point");
212 printf ("\n%s", narrow_margin);
214 printf ("%-*s", LEFT_COLUMN + 2, "");
215 print " Used Free Total ";
224 printf ("</TABLE>\n");
226 printf ("<!-- FIN CONTENU -->\n");
231 printf ("%s", narrow_margin);
233 printf ("%-*s", LEFT_COLUMN + 2, "");
234 print "|----|----|----|----|----|----|----|----|----|----|"
236 printf ("\n%s", narrow_margin);
238 printf ("%-*s", LEFT_COLUMN + 2, "");
239 print "0 10 20 30 40 50 60 70 80 90 100";
246 if (index ($0, "members") == 0 && index ($0, "Download") == 0 && index ($0, "admin") == 0)
248 # df -k shows k_bytes!
250 total_size = $2 * k_bytes;
251 free_size = $4 * k_bytes;
252 percentage_occupied = substr($5, 0, 3);
255 percentage_free = int (100 - percentage_occupied);
257 # reduction_factor: 2
258 stars_number = int (percentage_occupied / 2);
262 posGroup = index (mount_point, "scratch");
264 posGroup = index (mount_point, "u1");
266 posGroup = index (mount_point, "u2");
268 posGroup = index (mount_point, "u4");
270 posGroup = index (mount_point, "u5");
274 if (posGroup > 0 || percentage_free < free_threshold)
276 if (percentage_free < free_threshold)
280 posGroup = 1; # to display the whole mount_point in this color anyway
282 else if ((index (mount_point, "scratch") != 0) || (index (mount_point, "u1") != 0) || (index (mount_point, "u2") != 0))
284 class = "titleorange";
285 posGroup = 1; # to display the whole mount_point in this color
287 else if ((index (mount_point, "u4") != 0) || (index (mount_point, "u5") != 0))
289 class = "titlebrown";
290 posGroup = 1; # to display the whole mount_point in this color
294 "<TD ALIGN=LEFT>%s<SPAN CLASS=\"%s\">%s</SPAN></TD>\n",
295 substr (mount_point, 1, posGroup - 1),
297 substr (mount_point, posGroup) );
301 printf ("<TD ALIGN=LEFT>%s</TD>\n", mount_point);
305 "<TD ALIGN=CENTER><SPAN CLASS=\"titleblue\">%s</SPAN><SPAN CLASS=\"titlegreen\">%s</SPAN></TD>\n",
306 substr (all_stars, 1, stars_number), substr (all_stars, stars_number + 1, 49) );
308 if (percentage_free < free_threshold)
310 color_beginning = "<SPAN CLASS=\"titlered\">";
311 color_end = "</SPAN>"
315 color_beginning = "";
319 if (total_size > 1 * t_bytes)
321 "<TD ALIGN=RIGHT>%s%3d%%%s</TD><TD ALIGN=RIGHT>%5.1f Tb</TD><TD ALIGN=RIGHT>%5.1f Tb</TD>\n", \
322 color_beginning, percentage_occupied, color_end, free_size / t_bytes, total_size / t_bytes \
324 else if (total_size > 1 * g_bytes)
326 "<TD ALIGN=RIGHT>%s%3d%%%s</TD><TD ALIGN=RIGHT>%5.1f Gb</TD><TD ALIGN=RIGHT>%5.1f Gb</TD>\n", \
327 color_beginning, percentage_occupied, color_end, free_size / g_bytes, total_size / g_bytes \
329 else if (total_size > 1 * m_byptes)
331 "<TD ALIGN=RIGHT>%s%3d%%%s</TD><TD ALIGN=RIGHT>%5.1f Mb</TD><TD ALIGN=RIGHT>%5.1f Mb</TD>\n", \
332 color_beginning, percentage_occupied, color_end, free_size / m_bytes, total_size / m_bytes \
336 "<TD ALIGN=RIGHT>%s%3d%%%s</TD><TD ALIGN=RIGHT>%5.1f Kb</TD><TD ALIGN=RIGHT>%5.1f Kb</TD>\n", \
337 color_beginning, percentage_occupied, color_end, free_size / k_bytes, total_size / k_bytes \
345 # printf ("percentage_occupied = %d\n", percentage_occupied);
346 # printf ("percentage_free = %d\n", percentage_free);
348 printf ("%-*s", LEFT_COLUMN + 2, mount_point);
350 printf ("\n%s", narrow_margin);
352 # printf ("stars_number = %d\n", stars_number);
355 for (i = 1; i <= stars_number; i++)
359 for (i = stars_number + 1; i <= 49; i++)
365 if (total_size > 1 * t_bytes)
367 "| %3d%% %5.1f %5.1f Tb\n", \
368 percentage_occupied, free_size / t_bytes, total_size / t_bytes \
370 else if (total_size > 1 * g_bytes)
372 "| %3d%% %5.1f %5.1f Gb\n", \
373 percentage_occupied, free_size / g_bytes, total_size / g_bytes \
375 else if (total_size > 1 * m_byptes)
377 "| %3d%% %5.1f %5.1f Mb\n", \
378 percentage_occupied, free_size / m_bytes, total_size / m_bytes \
382 "| %3d%% %5.1f %5.1f Kb\n", \
383 percentage_occupied, free_size / k_bytes, total_size / k_bytes \