From 091612802226a9aa3fb8538a9eef8e3bcfe74669 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Fri, 04 May 2018 01:38:16 -0400 Subject: bin/df-uptime: New script --- diff --git a/bin/df-uptime b/bin/df-uptime new file mode 100755 index 0000000..64ac8b4 --- /dev/null +++ b/bin/df-uptime @@ -0,0 +1,110 @@ +#!/bin/sh + +set -eu + +indent='' +le="$(printf '\n.')"; le="${le%.}" + +err() +{ + local fmt="${1}" + shift 1 + + printf "Error: ${fmt}\n" "${@}" 1>&2 + return 0 +} + +gen_indent() +{ + local l=${1} + shift 1 + local i= + + i=0 + while [ ${i} -lt ${l} ]; do + indent="${indent} " + i=$((${i} + 1)) + done + + return 0 +} + +do_df() +{ + local sed_bre= + + sed_bre='^..* *..* *..* *..* *\([0-9][0-9]*%\) \(..*\)$' + df -h -x devtmpfs -x tmpfs | \ + sed "1d; s/${sed_bre}/${indent}\\1 \\2/;" | tr '\n' "${le}" + + return 0 +} + +do_uptime() +{ + local up= + local idle= + local min= + local hr= + local day= + + read -r up idle 0]\n' "${0}" + printf '\n' + printf 'Options:\n' + printf ' -i Indent lines with spaces\n' + printf ' -r Print carriage returns instead of line feeds\n' + + return 0 +} + +main() +{ + local opt= + + while getopts 'i:r' opt "${@}"; do + case "${opt}" in + 'i') + case "${OPTARG}" in *[!0-9]* | '') + usage 1>&2 + return 1 + esac + gen_indent ${OPTARG} + ;; + 'r') le="$(printf '\r.')"; le="${le%.}";; + '?') + usage 1>&2 + return 1 + ;; + esac + done + shift $((${OPTIND} - 1)) + + if [ ${#} -ne 0 ]; then + usage 1>&2 + return 1 + fi + + do_df + do_uptime + + return 0 +} + +main "${@}" -- cgit v0.9.1