From 25790ca604d8c7d7ef651f12b1322213b8d32460 Mon Sep 17 00:00:00 2001 From: Igor Pecovnik Date: Mon, 26 Jan 2026 19:55:12 +0100 Subject: [PATCH] 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. --- .../etc/update-motd.d/30-armbian-sysinfo | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/packages/bsp/common/etc/update-motd.d/30-armbian-sysinfo b/packages/bsp/common/etc/update-motd.d/30-armbian-sysinfo index 20921f2832..262349e6ee 100755 --- a/packages/bsp/common/etc/update-motd.d/30-armbian-sysinfo +++ b/packages/bsp/common/etc/update-motd.d/30-armbian-sysinfo @@ -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 ""