2024-02-09 19:18:33 +01:00
|
|
|
print_uptime() {
|
|
|
|
local HOST=$1
|
|
|
|
local EMOJI=$2
|
|
|
|
|
|
|
|
# -n: do not echo a newline
|
2024-02-12 19:33:31 +01:00
|
|
|
echo -n "$EMOJI $HOST: ~"
|
2024-02-09 19:18:33 +01:00
|
|
|
|
|
|
|
# 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`,
|
|
|
|
# so we use awk to trim it down to the parts we care about.
|
|
|
|
#
|
|
|
|
# For awk:
|
|
|
|
# -F: splits the input by a string
|
2024-05-21 01:37:39 +02:00
|
|
|
ssh $USER@$HOST uptime \
|
2024-02-12 19:33:31 +01:00
|
|
|
| awk -F '(up |,)' '{print $2}'
|
2024-02-09 19:18:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
echo "Uptimes:"
|
2024-02-12 19:33:31 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
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
|
2024-05-09 04:12:28 +02:00
|
|
|
# -s ~ will split on occurrences of ~
|