yet-another-bench-script
yet-another-bench-script copied to clipboard
Erroneous reported uptime when minutes is 0
As reported by lukast__ at LowEndSpirit:
I just had a YABS with a weird uptime when the system is up X days, 0 hours and Y minutes:
# ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #
# Yet-Another-Bench-Script #
# v2024-06-09 #
# https://github.com/masonr/yet-another-bench-script #
# ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #
Fri Jul 5 07:15:24 PM CEST 2024
Basic System Information:
---------------------------------
Uptime : 2 days, 37 hours, 0 minutes
Processor : AMD EPYC 9754 128-Core Processor
CPU cores : 6 @ 2595.124 MHz
AES-NI : ✔ Enabled
VM-x/AMD-V : ✔ Enabled
RAM : 15.6 GiB
Swap : 1024.0 MiB
Disk : 314.9 GiB
Distro : Debian GNU/Linux 12 (bookworm)
Kernel : 6.1.0-22-amd64
VM Type : KVM
IPv4/IPv6 : ✔ Online / ✔ Online
The real uptime is "19:15:28 up 2 days, 37 min, 2 users, load average: 2.11, 1.46, 1.17", so it seems YABS is parsing it incorrectly. An easy fix would be to replace line 215 with:
UPTIME=$(uptime | awk -F'( |,|:)+' '{d=h=m=0; if ($7=="min") m=$6; else {if ($7~/^day/) {d=$6; if ($9~/^min/) m=$8; else {h=$8;m=$9}} else {h=$6;m=$7}}} {print d+0,"days,",h+0,"hours,",m+0,"minutes"}')
But is there any reason you're not simply using uptime --pretty
?