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
 
   9 # -------------------------------------------------------------------------
 
  11 # -------------------------------------------------------------------------
 
  12 USAGE="Usage: $0 [-h(elp)] | [-n(arrow mode)] | [-w(eb output)]"
 
  17 while [ $# -gt 0 ]; do
 
  40 # -------------------------------------------------------------------------
 
  42 # -------------------------------------------------------------------------
 
  48 DF_COMMAND="/usr/bin/env df -k"
 
  49 SORT_COMMAND="/usr/bin/env sort -k6"
 
  50 AWK_COMMAND="/usr/bin/env awk"
 
  53 DF_COMMAND="/bin/df -k"
 
  54 SORT_COMMAND="/usr/bin/sort -k6"
 
  55 AWK_COMMAND="/usr/bin/env gawk"
 
  59 # -------------------------------------------------------------------------
 
  60 #   Grabbing "df" result
 
  61 # -------------------------------------------------------------------------
 
  62 DF_RESULT=`$DF_COMMAND`
 
  63 if [ ! -z $DEBUG ]; then
 
  69 # -------------------------------------------------------------------------
 
  70 #   Preprocessing "df" result, to join split logical lines
 
  71 # -------------------------------------------------------------------------
 
  72 PREPROCESSING_RESULT=` \
 
  73                                                                                  echo "$DF_RESULT" | $AWK_COMMAND -v PATTERN=$PATTERN \
 
  90 if [ ! -z $DEBUG ]; then
 
  91 echo "--> PREPROCESSING_RESULT:"
 
  92 echo "$PREPROCESSING_RESULT"
 
  96 SORTED_FILE_SYSTEMS_INFO=`echo "$PREPROCESSING_RESULT" | $SORT_COMMAND`
 
  98 if [ ! -z $DEBUG ]; then
 
  99 echo "--> SORTED_FILE_SYSTEMS_INFO:"
 
 100 echo "$SORTED_FILE_SYSTEMS_INFO"
 
 104 # -------------------------------------------------------------------------
 
 105 #   Computing mount point max length
 
 106 # -------------------------------------------------------------------------
 
 107 MOUNT_POINT_MAX_LENGTH=` \
 
 108                                                                                          echo $SORTED_FILE_SYSTEMS_INFO | $AWK_COMMAND -v PATTERN=$PATTERN \
 
 111                                                                                                  mount_point_length_max = 15;
 
 115         printf ("%d", mount_point_length_max);
 
 119 #       printf ("$6 = %s\n", $6);
 
 122 #       printf ("mount_point = %s\n", mount_point);
 
 124         mount_point_length = length (mount_point);
 
 125 #       printf ("mount_point_length = %d\n", mount_point_length);
 
 127         if (mount_point_length > mount_point_length_max)
 
 128                 mount_point_length_max = mount_point_length;
 
 131 if [ ! -z $DEBUG ]; then
 
 132 echo "MOUNT_POINT_MAX_LENGTH:      $MOUNT_POINT_MAX_LENGTH"
 
 135 # -------------------------------------------------------------------------
 
 136 #   Computing mount point data max size
 
 137 # -------------------------------------------------------------------------
 
 138 MOUNT_POINT_MAX_SIZE=` \
 
 139                                                                                  echo "$SORTED_FILE_SYSTEMS_INFO" | $AWK_COMMAND -v PATTERN=$PATTERN \
 
 142                                                                                          mount_point_size_max = 0;
 
 146         printf ("%d", mount_point_size_max);
 
 150 #       df -k shows k_bytes!
 
 151 #       printf ("$2 = %s\n", $2);
 
 153         mount_point_size = $2 * 1024;
 
 154 #       printf ("mount_point_size = %d\n", mount_point_size);
 
 156         if (mount_point_size > mount_point_size_max)
 
 157                 mount_point_size_max = mount_point_size;
 
 160 if [ ! -z $DEBUG ]; then
 
 161 echo "MOUNT_POINT_MAX_SIZE:      $MOUNT_POINT_MAX_SIZE"
 
 164 # -------------------------------------------------------------------------
 
 166 # -------------------------------------------------------------------------
 
 167 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 \
 
 169 #   {printf ("$0 = %s\n", $0);}
 
 170 #   {printf ("$1 = %s\n", $1);}
 
 171 #   {printf ("PATTERN = %s\n", PATTERN);}
 
 172 #   {printf ("LEFT_COLUMN = %s\n", LEFT_COLUMN);}
 
 176                                  m_bytes = 1024.0 * k_bytes;
 
 177                                  g_bytes = 1024.0 * m_bytes;
 
 178                                  t_bytes = 1024.0 * g_bytes;
 
 182                                          all_stars = "**************************************************";
 
 183                                          current_date = strftime ("%d-%m-%Y @ %H:%M:%S", localtime (systime ()));
 
 184                                          free_threshold = 10; # %
 
 186                                                  printf ("<!-- DEBUT CONTENU -->\n");
 
 189                                                          "<A NAME=\"top\"></A>\n" \
 
 190                                                          "<P ALIGN=CENTER><SPAN CLASS=\"titleblue\">%s</SPAN><SPAN CLASS=\"textbold\">  --  STATUS OF <SPAN CLASS=\"titlered\">ALCOR</SPAN> FILE SYSTEMS</SPAN></P><BR>\n",
 
 193                                                  printf ("<TABLE WIDTH=\"100%%\" BORDER=1>\n");
 
 197                                                          "<TD ALIGN=LEFT><STRONG>Mount point</STRONG></TD>\n" \
 
 198                                                          "<TD ALIGN=CENTER><STRONG>%% Usato (<SPAN CLASS=\"titleblue\">*</SPAN>)" \
 
 199                                                          " - %% Free (<SPAN CLASS=\"titlegreen\">*</SPAN>)</STRONG></TD>\n" \
 
 200                                                          "<TD ALIGN=CENTER><STRONG>%% Usato</STRONG></TD>\n" \
 
 201                                                          "<TD ALIGN=CENTER><STRONG>Spazio libero</STRONG></TD>\n" \
 
 202                                                          "<TD ALIGN=CENTER><STRONG>Spazio totale</STRONG></TD>\n" \
 
 208 #           printf ("%-*s", LEFT_COLUMN + 2, "Mount point");
 
 210                                                          printf ("\n%s", narrow_margin);
 
 212                                                          printf ("%-*s", LEFT_COLUMN + 2, "");
 
 213                                          print "                                                     Used    Free     Total ";
 
 222                 printf ("</TABLE>\n");
 
 224                 printf ("<!-- FIN CONTENU -->\n");
 
 229                         printf ("%s", narrow_margin);
 
 231                         printf ("%-*s", LEFT_COLUMN + 2, "");
 
 232                 print "|----|----|----|----|----|----|----|----|----|----|"
 
 234                                 printf ("\n%s", narrow_margin);
 
 236                                 printf ("%-*s", LEFT_COLUMN + 2, "");
 
 237                 print "0   10   20   30   40   50   60   70   80   90  100";
 
 244         if (index ($0, "members") == 0 && index ($0, "Download") == 0 && index ($0, "admin") == 0)
 
 246 #       df -k shows k_bytes!
 
 248                 total_size = $2 * k_bytes;
 
 249                 free_size = $4 * k_bytes;
 
 250                 percentage_occupied = substr($5, 0, 3);
 
 253                 percentage_free = int (100 - percentage_occupied);
 
 255 #       reduction_factor: 2
 
 256                 stars_number = int (percentage_occupied / 2);
 
 260                         posGroup = index (mount_point, "scratch");
 
 262                                 posGroup = index (mount_point, "u1");
 
 264                                 posGroup = index (mount_point, "u2");
 
 266                                 posGroup = index (mount_point, "u4");
 
 268                                 posGroup = index (mount_point, "u5");
 
 272                         if (posGroup > 0 || percentage_free < free_threshold)
 
 274                                 if (percentage_free < free_threshold)
 
 278                                                 posGroup = 1;   # to display the whole mount_point in this color anyway
 
 280                                 else if ((index (mount_point, "scratch") != 0) || (index (mount_point, "u1") != 0) || (index (mount_point, "u2") != 0))
 
 282                                         class = "titleorange";
 
 283                                         posGroup = 1;   # to display the whole mount_point in this color
 
 285                                 else if ((index (mount_point, "u4") != 0) || (index (mount_point, "u5") != 0))
 
 287                                         class = "titlebrown";
 
 288                                         posGroup = 1;   # to display the whole mount_point in this color
 
 292                                                 "<TD ALIGN=LEFT>%s<SPAN CLASS=\"%s\">%s</SPAN></TD>\n",
 
 293                                                 substr (mount_point, 1, posGroup - 1),
 
 295                                                 substr (mount_point, posGroup) );
 
 299                                 printf ("<TD ALIGN=LEFT>%s</TD>\n", mount_point);
 
 303                                         "<TD ALIGN=CENTER><SPAN CLASS=\"titleblue\">%s</SPAN><SPAN CLASS=\"titlegreen\">%s</SPAN></TD>\n",
 
 304                                         substr (all_stars, 1, stars_number), substr (all_stars, stars_number + 1, 49) );
 
 306                         if (percentage_free < free_threshold)
 
 308                                 color_beginning = "<SPAN CLASS=\"titlered\">";
 
 309                                 color_end = "</SPAN>"
 
 313                                 color_beginning = "";
 
 317                         if (total_size > 1 * t_bytes)
 
 319                                                 "<TD ALIGN=RIGHT>%s%3d%%%s</TD><TD ALIGN=RIGHT>%5.1f Tb</TD><TD ALIGN=RIGHT>%5.1f Tb</TD>\n", \
 
 320                                                 color_beginning, percentage_occupied, color_end, free_size / t_bytes, total_size / t_bytes \
 
 322                         else if (total_size > 1 * g_bytes)
 
 324                                                 "<TD ALIGN=RIGHT>%s%3d%%%s</TD><TD ALIGN=RIGHT>%5.1f Gb</TD><TD ALIGN=RIGHT>%5.1f Gb</TD>\n", \
 
 325                                                 color_beginning, percentage_occupied, color_end, free_size / g_bytes, total_size / g_bytes \
 
 327                         else if (total_size > 1 * m_byptes)
 
 329                                                 "<TD ALIGN=RIGHT>%s%3d%%%s</TD><TD ALIGN=RIGHT>%5.1f Mb</TD><TD ALIGN=RIGHT>%5.1f Mb</TD>\n", \
 
 330                                                 color_beginning, percentage_occupied, color_end, free_size / m_bytes, total_size / m_bytes \
 
 334                                                 "<TD ALIGN=RIGHT>%s%3d%%%s</TD><TD ALIGN=RIGHT>%5.1f Kb</TD><TD ALIGN=RIGHT>%5.1f Kb</TD>\n", \
 
 335                                                 color_beginning, percentage_occupied, color_end, free_size / k_bytes, total_size / k_bytes \
 
 343 #           printf ("percentage_occupied = %d\n", percentage_occupied);
 
 344 #           printf ("percentage_free = %d\n", percentage_free);
 
 346                         printf ("%-*s", LEFT_COLUMN + 2, mount_point);
 
 348                                 printf ("\n%s", narrow_margin);
 
 350 #           printf ("stars_number = %d\n", stars_number);
 
 353                         for (i = 1; i <= stars_number; i++)
 
 357                         for (i = stars_number + 1; i <= 49; i++)
 
 363                         if (total_size > 1 * t_bytes)
 
 365                                                 "| %3d%%    %5.1f    %5.1f Tb\n", \
 
 366                                                 percentage_occupied, free_size / t_bytes, total_size / t_bytes \
 
 368                         else if (total_size > 1 * g_bytes)
 
 370                                                 "| %3d%%    %5.1f    %5.1f Gb\n", \
 
 371                                                 percentage_occupied, free_size / g_bytes, total_size / g_bytes \
 
 373                         else if (total_size > 1 * m_byptes)
 
 375                                                 "| %3d%%    %5.1f    %5.1f Mb\n", \
 
 376                                                 percentage_occupied, free_size / m_bytes, total_size / m_bytes \
 
 380                                                 "| %3d%%    %5.1f    %5.1f Kb\n", \
 
 381                                                 percentage_occupied, free_size / k_bytes, total_size / k_bytes \