@parseUpTime()

Runs the "uptime" command, parses the output and sets variables.

This command runs "uptime" and parses the results. The individual values parsed are stored in the variables: UPTIME_UP_DAYS, UPTIME_UP_HOURS_MINS, UPTIME_USERS, UPTIME_LOAD_1MIN, UPTIME_LOAD_5MIN, and UPTIME_LOAD_15MIN. One does not typically use this macro directly as it is included when the top level banner is displayed. After the top level banner of the HTML page has been rendered, one has access to all of the above variables.

This macro is defined as:

check_required_program AWK awk;
check_required_program UPTIME uptime;

# Set defaults (in case something goes wrong)
UPTIME_UP_DAYS='0';
UPTIME_UP_HOURS_MINS='00:00';
UPTIME_USERS='0';
UPTIME_LOAD_1MIN='0.00';
UPTIME_LOAD_5MIN='0.00';
UPTIME_LOAD_15MIN='0.00';

eval $(${UPTIME} | xml_escape | ${AWK} -- '

#
# If up for less than 1 day but less than 1 hour, no "N days,":
# 0 days, minute mode...
$4 == "min," {
  printf("UPTIME_UP_DAYS=\"%s\";\n", 0);
  printf("UPTIME_UP_HOURS_MINS=\"0:%02d\";\n", $3);
  printf("UPTIME_USERS=\"%s\";\n", $5);
  printf("UPTIME_LOAD_1MIN=\"%s\";\n", substr($9, 0, length($9) - 1));
  printf("UPTIME_LOAD_5MIN=\"%s\";\n", substr($10, 0, length($10) - 1));
  printf("UPTIME_LOAD_15MIN=\"%s\";\n", $11);
}

#
# If up for less than 1 day but greater than 1 hour, no "N days,":
# 0 days, hour:minute mode...
$6 == "load" {
  printf("UPTIME_UP_DAYS=\"%s\";\n", 0);
  printf("UPTIME_UP_HOURS_MINS=\"%s\";\n", substr($3, 0, length($3) - 1));
  printf("UPTIME_USERS=\"%s\";\n", $4);
  printf("UPTIME_LOAD_1MIN=\"%s\";\n", substr($8, 0, length($8) - 1));
  printf("UPTIME_LOAD_5MIN=\"%s\";\n", substr($9, 0, length($9) - 1));
  printf("UPTIME_LOAD_15MIN=\"%s\";\n", $10);
}

#
# If up for 1 day but less than 1 hour:
# 1 day, minute mode...
$4 == "day," && $6 == "min," {
  printf("UPTIME_UP_DAYS=\"%s\";\n", $3);
  printf("UPTIME_UP_HOURS_MINS=\"0:%02d\";\n", $5);
  printf("UPTIME_USERS=\"%s\";\n", $7);
  printf("UPTIME_LOAD_1MIN=\"%s\";\n", substr($11, 0, length($11) - 1));
  printf("UPTIME_LOAD_5MIN=\"%s\";\n", substr($12, 0, length($12) - 1));
  printf("UPTIME_LOAD_15MIN=\"%s\";\n", $13);
}

#
# If up for 1 day but more than one hour that day:
# 1 day, hour:minute mode...
$4 == "day," && $6 != "min," {
  printf("UPTIME_UP_DAYS=\"%s\";\n", $3);
  printf("UPTIME_UP_HOURS_MINS=\"%s\";\n", substr($5, 0, length($5) - 1));
  printf("UPTIME_USERS=\"%s\";\n", $6);
  printf("UPTIME_LOAD_1MIN=\"%s\";\n", substr($10, 0, length($10) - 1));
  printf("UPTIME_LOAD_5MIN=\"%s\";\n", substr($11, 0, length($11) - 1));
  printf("UPTIME_LOAD_15MIN=\"%s\";\n", $12);
}

#
# If up more than 1 day and less than 1 hour:
# 2+ days, minute mode...
$4 == "days," && $6 == "min," {
  printf("UPTIME_UP_DAYS=\"%s\";\n", $3);
  printf("UPTIME_UP_HOURS_MINS=\"0:%02d\";\n", $5);
  printf("UPTIME_USERS=\"%s\";\n", $7);
  printf("UPTIME_LOAD_1MIN=\"%s\";\n", substr($11, 0, length($11) - 1));
  printf("UPTIME_LOAD_5MIN=\"%s\";\n", substr($12, 0, length($12) - 1));
  printf("UPTIME_LOAD_15MIN=\"%s\";\n", $13);
}

#
# If up more than 1 day and greater than 1 hour:
# 2+ days, hour:minute  mode...
$4 == "days," && $6 != "min," {
  printf("UPTIME_UP_DAYS=\"%s\";\n", $3);
  printf("UPTIME_UP_HOURS_MINS=\"%s\";\n", substr($5, 0, length($5) - 1));
  printf("UPTIME_USERS=\"%s\";\n", $6);
  printf("UPTIME_LOAD_1MIN=\"%s\";\n", substr($10, 0, length($10) - 1));
  printf("UPTIME_LOAD_5MIN=\"%s\";\n", substr($11, 0, length($11) - 1));
  printf("UPTIME_LOAD_15MIN=\"%s\";\n", $12);
}');