fix: motd: simplify uptime display format and align properly

Replace verbose "1 day, 6 hours, 17 minutes" format with compact
"1d 6h" style for better readability. Fix alignment with Load
and Local users fields. Reads uptime directly from /proc/uptime.
This commit is contained in:
Igor Pecovnik 2026-01-26 19:55:12 +01:00 committed by Igor
parent ad45d09ca4
commit 25790ca604

View File

@ -96,8 +96,25 @@ critical_load=80
# Uptime, users, and load
users="$(who 2>/dev/null | wc -l | tr -d ' ')"
time="$(uptime -p 2>/dev/null | sed -e 's/^up //')"
[[ -z "$time" ]] && time="$(LC_ALL=C uptime | sed -E 's/.*up ([^,]+), .*/\1/')"
# Format uptime compactly: "1d 6h", "6h 17m", "17m", etc.
format_uptime() {
local uptime_sec=$(cat /proc/uptime | awk '{print int($1)}')
local days=$((uptime_sec / 86400))
local hours=$(((uptime_sec % 86400) / 3600))
local minutes=$(((uptime_sec % 3600) / 60))
local parts=()
(( days > 0 )) && parts+=("${days}d")
(( hours > 0 )) && parts+=("${hours}h")
(( minutes > 0 )) && parts+=("${minutes}m")
# If system just started, show 1m
((${#parts[@]} == 0)) && parts=("1m")
echo "${parts[*]}"
}
time="$(format_uptime)"
cpucount="$(grep -c ^processor /proc/cpuinfo 2>/dev/null || echo 1)"
read -r load1 _ < /proc/loadavg
@ -134,7 +151,7 @@ fi
printf "\e[0;90m Performance: \x1B[0m\n\n"
display " Load" "${load%% *}" "$critical_load" "0" "%" ""
printf " Uptime: \x1B[92m%s\x1B[0m\t" "${time:-unknown}"
printf " Uptime: \x1B[92m%s\x1B[0m\t" "${time:-unknown}"
display " Local users" "${users:-0}" "3" "2" "" ""
echo ""