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/lcpz/lain
11 # -------------------------------------------------------------------------
13 # -------------------------------------------------------------------------
14 USAGE="Usage: $0 [-h(elp)] | [-n(arrow mode)] | [-w(eb output) | --type=<fstype> | --exclude-type=<fstype>]"
20 while [ $# -gt 0 ]; do
49 # -------------------------------------------------------------------------
51 # -------------------------------------------------------------------------
57 DF_COMMAND="/usr/bin/env df -k"
58 SORT_COMMAND="/usr/bin/env sort -k6"
59 AWK_COMMAND="/usr/bin/env awk"
62 DF_COMMAND="/bin/df -k"
63 SORT_COMMAND="/usr/bin/sort -k6"
64 AWK_COMMAND="/usr/bin/env gawk"
68 # Add additional df options
69 DF_COMMAND+=$DF_OPTIONS
71 # -------------------------------------------------------------------------
72 # Grabbing "df" result
73 # -------------------------------------------------------------------------
74 DF_RESULT=`$DF_COMMAND`
75 if [ ! -z $DEBUG ]; then
81 # -------------------------------------------------------------------------
82 # Preprocessing "df" result, to join split logical lines
83 # -------------------------------------------------------------------------
84 PREPROCESSING_RESULT=` \
85 echo "$DF_RESULT" | $AWK_COMMAND -v PATTERN=$PATTERN \
102 if [ ! -z $DEBUG ]; then
103 echo "--> PREPROCESSING_RESULT:"
104 echo "$PREPROCESSING_RESULT"
108 SORTED_FILE_SYSTEMS_INFO=`echo "$PREPROCESSING_RESULT" | $SORT_COMMAND`
110 if [ ! -z $DEBUG ]; then
111 echo "--> SORTED_FILE_SYSTEMS_INFO:"
112 echo "$SORTED_FILE_SYSTEMS_INFO"
116 # -------------------------------------------------------------------------
117 # Computing mount point max length
118 # -------------------------------------------------------------------------
119 MOUNT_POINT_MAX_LENGTH=` \
120 echo "$SORTED_FILE_SYSTEMS_INFO" | $AWK_COMMAND -v PATTERN=$PATTERN \
123 mount_point_length_max = 15;
127 printf ("%d", mount_point_length_max);
131 # printf ("$6 = %s\n", $6);
134 # printf ("mount_point = %s\n", mount_point);
136 mount_point_length = length (mount_point);
137 # printf ("mount_point_length = %d\n", mount_point_length);
139 if (mount_point_length > mount_point_length_max)
140 mount_point_length_max = mount_point_length;
143 if [ ! -z $DEBUG ]; then
144 echo "MOUNT_POINT_MAX_LENGTH: $MOUNT_POINT_MAX_LENGTH"
147 # -------------------------------------------------------------------------
148 # Computing mount point data max size
149 # -------------------------------------------------------------------------
150 MOUNT_POINT_MAX_SIZE=` \
151 echo "$SORTED_FILE_SYSTEMS_INFO" | $AWK_COMMAND -v PATTERN=$PATTERN \
154 mount_point_size_max = 0;
158 printf ("%d", mount_point_size_max);
162 # df -k shows k_bytes!
163 # printf ("$2 = %s\n", $2);
165 mount_point_size = $2 * 1024;
166 # printf ("mount_point_size = %d\n", mount_point_size);
168 if (mount_point_size > mount_point_size_max)
169 mount_point_size_max = mount_point_size;
172 if [ ! -z $DEBUG ]; then
173 echo "MOUNT_POINT_MAX_SIZE: $MOUNT_POINT_MAX_SIZE"
176 # -------------------------------------------------------------------------
178 # -------------------------------------------------------------------------
179 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 \
181 # {printf ("$0 = %s\n", $0);}
182 # {printf ("$1 = %s\n", $1);}
183 # {printf ("PATTERN = %s\n", PATTERN);}
184 # {printf ("LEFT_COLUMN = %s\n", LEFT_COLUMN);}
188 m_bytes = 1024.0 * k_bytes;
189 g_bytes = 1024.0 * m_bytes;
190 t_bytes = 1024.0 * g_bytes;
194 all_stars = "**************************************************";
195 current_date = strftime ("%d-%m-%Y @ %H:%M:%S", localtime (systime ()));
196 free_threshold = 10; # %
198 printf ("<!-- DEBUT CONTENU -->\n");
201 "<A NAME=\"top\"></A>\n" \
202 "<P ALIGN=CENTER><SPAN CLASS=\"titleblue\">%s</SPAN><SPAN CLASS=\"textbold\"> -- STATUS OF <SPAN CLASS=\"titlered\">ALCOR</SPAN> FILE SYSTEMS</SPAN></P><BR>\n",
205 printf ("<TABLE WIDTH=\"100%%\" BORDER=1>\n");
209 "<TD ALIGN=LEFT><STRONG>Mount point</STRONG></TD>\n" \
210 "<TD ALIGN=CENTER><STRONG>%% Usato (<SPAN CLASS=\"titleblue\">*</SPAN>)" \
211 " - %% Free (<SPAN CLASS=\"titlegreen\">*</SPAN>)</STRONG></TD>\n" \
212 "<TD ALIGN=CENTER><STRONG>%% Used</STRONG></TD>\n" \
213 "<TD ALIGN=CENTER><STRONG>Free</STRONG></TD>\n" \
214 "<TD ALIGN=CENTER><STRONG>Total</STRONG></TD>\n" \
220 # printf ("%-*s", LEFT_COLUMN + 2, "Mount point");
222 printf ("\n%s", narrow_margin);
224 printf ("%-*s", LEFT_COLUMN + 2, "");
225 print " Used Free Total ";
234 printf ("</TABLE>\n");
236 printf ("<!-- FIN CONTENU -->\n");
241 printf ("%s", narrow_margin);
243 printf ("%-*s", LEFT_COLUMN + 2, "");
244 print "|----|----|----|----|----|----|----|----|----|----|"
246 printf ("\n%s", narrow_margin);
248 printf ("%-*s", LEFT_COLUMN + 2, "");
249 print "0 10 20 30 40 50 60 70 80 90 100";
256 if (index ($0, "members") == 0 && index ($0, "Download") == 0 && index ($0, "admin") == 0)
258 # df -k shows k_bytes!
260 total_size = $2 * k_bytes;
261 free_size = $4 * k_bytes;
262 percentage_occupied = substr($5, 0, 3);
265 percentage_free = int (100 - percentage_occupied);
267 # reduction_factor: 2
268 stars_number = int (percentage_occupied / 2);
272 posGroup = index (mount_point, "scratch");
274 posGroup = index (mount_point, "u1");
276 posGroup = index (mount_point, "u2");
278 posGroup = index (mount_point, "u4");
280 posGroup = index (mount_point, "u5");
284 if (posGroup > 0 || percentage_free < free_threshold)
286 if (percentage_free < free_threshold)
290 posGroup = 1; # to display the whole mount_point in this color anyway
292 else if ((index (mount_point, "scratch") != 0) || (index (mount_point, "u1") != 0) || (index (mount_point, "u2") != 0))
294 class = "titleorange";
295 posGroup = 1; # to display the whole mount_point in this color
297 else if ((index (mount_point, "u4") != 0) || (index (mount_point, "u5") != 0))
299 class = "titlebrown";
300 posGroup = 1; # to display the whole mount_point in this color
304 "<TD ALIGN=LEFT>%s<SPAN CLASS=\"%s\">%s</SPAN></TD>\n",
305 substr (mount_point, 1, posGroup - 1),
307 substr (mount_point, posGroup) );
311 printf ("<TD ALIGN=LEFT>%s</TD>\n", mount_point);
315 "<TD ALIGN=CENTER><SPAN CLASS=\"titleblue\">%s</SPAN><SPAN CLASS=\"titlegreen\">%s</SPAN></TD>\n",
316 substr (all_stars, 1, stars_number), substr (all_stars, stars_number + 1, 49) );
318 if (percentage_free < free_threshold)
320 color_beginning = "<SPAN CLASS=\"titlered\">";
321 color_end = "</SPAN>"
325 color_beginning = "";
329 if (total_size > 1 * t_bytes)
331 "<TD ALIGN=RIGHT>%s%3d%%%s</TD><TD ALIGN=RIGHT>%5.1f Tb</TD><TD ALIGN=RIGHT>%5.1f Tb</TD>\n", \
332 color_beginning, percentage_occupied, color_end, free_size / t_bytes, total_size / t_bytes \
334 else if (total_size > 1 * g_bytes)
336 "<TD ALIGN=RIGHT>%s%3d%%%s</TD><TD ALIGN=RIGHT>%5.1f Gb</TD><TD ALIGN=RIGHT>%5.1f Gb</TD>\n", \
337 color_beginning, percentage_occupied, color_end, free_size / g_bytes, total_size / g_bytes \
339 else if (total_size > 1 * m_byptes)
341 "<TD ALIGN=RIGHT>%s%3d%%%s</TD><TD ALIGN=RIGHT>%5.1f Mb</TD><TD ALIGN=RIGHT>%5.1f Mb</TD>\n", \
342 color_beginning, percentage_occupied, color_end, free_size / m_bytes, total_size / m_bytes \
346 "<TD ALIGN=RIGHT>%s%3d%%%s</TD><TD ALIGN=RIGHT>%5.1f Kb</TD><TD ALIGN=RIGHT>%5.1f Kb</TD>\n", \
347 color_beginning, percentage_occupied, color_end, free_size / k_bytes, total_size / k_bytes \
355 # printf ("percentage_occupied = %d\n", percentage_occupied);
356 # printf ("percentage_free = %d\n", percentage_free);
358 printf ("%-*s", LEFT_COLUMN + 2, mount_point);
360 printf ("\n%s", narrow_margin);
362 # printf ("stars_number = %d\n", stars_number);
365 for (i = 1; i <= stars_number && i <= 49; i++)
369 for (i = stars_number + 1; i <= 49; i++)
375 if (total_size > 1 * t_bytes)
377 "| %3d%% %6.1f %6.1f Tb\n", \
378 percentage_occupied, free_size / t_bytes, total_size / t_bytes \
380 else if (total_size > 1 * g_bytes)
382 "| %3d%% %6.1f %6.1f Gb\n", \
383 percentage_occupied, free_size / g_bytes, total_size / g_bytes \
385 else if (total_size > 1 * m_byptes)
387 "| %3d%% %6.1f %6.1f Mb\n", \
388 percentage_occupied, free_size / m_bytes, total_size / m_bytes \
392 "| %3d%% %6.1f %6.1f Kb\n", \
393 percentage_occupied, free_size / k_bytes, total_size / k_bytes \