From 27eb310cce02e9933e79520c39a62fc7f9490cda Mon Sep 17 00:00:00 2001 From: Matei Adriel Date: Mon, 12 Feb 2024 19:33:31 +0100 Subject: [PATCH] Fix uptimes script parsing --- home/features/cli/scripts/uptimes.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/home/features/cli/scripts/uptimes.sh b/home/features/cli/scripts/uptimes.sh index a2bcfc5..0d420c7 100755 --- a/home/features/cli/scripts/uptimes.sh +++ b/home/features/cli/scripts/uptimes.sh @@ -3,7 +3,7 @@ print_uptime() { local EMOJI=$2 # -n: do not echo a newline - echo -n "$EMOJI $HOST: " + echo -n "$EMOJI $HOST: ~" # The output of `uptime` looks like this: # `18:40:54 up 1 day 0:51, 0 users, load average: 0.79, 0.68, 0.69`, @@ -12,10 +12,16 @@ print_uptime() { # For awk: # -F: splits the input by a string ssh adrielus@$HOST uptime \ - | awk -F "up" '{print $2}' \ - | awk -F " " '{print $1, $2}' + | awk -F '(up |,)' '{print $2}' } echo "Uptimes:" -print_uptime "tethys" "🔥" -print_uptime "lapetus" "⛵" + +{ + print_uptime "tethys" "🔥" + print_uptime "lapetus" "⛵" +} | +column --table -R 2 -s "~" +# ^ We use the column command to align things nicely: +# -R 2 aligns the second column to the right +# -s ~ will split on occurences of ~