# uptm: just show system uptime
2024-02-10T14:32:16Z
I find annoying to have current date, load averages, numbers or users next to system uptime in ''w'' or ''uptime''.
So, I modified w.c to just print uptime.
I find it handy in a status script for tmux or dwm.
```
/* modified w.c to only display uptime */
#include <sys/time.h>
#include <stdio.h>
#define SECSPERHOUR (60 * 60)
#define SECSPERDAY (24 * 60 * 60)
int
main(void)
{
struct timespec boottime;
time_t uptime, now;
int days, hrs, mins;
time(&now);
/*
* Print how long system has been up.
*/
if (clock_gettime(CLOCK_BOOTTIME, &boottime) != -1) {
uptime = boottime.tv_sec;
if (uptime > 59) {
uptime += 30;
days = uptime / SECSPERDAY;
uptime %= SECSPERDAY;
hrs = uptime / SECSPERHOUR;
uptime %= SECSPERHOUR;
mins = uptime / 60;
if (days > 0)
(void)printf("%d day%s", days,
days > 1 ? "s" : "");
if (hrs > 0 && mins > 0)
(void)printf("%2d:%02d", hrs, mins);
else {
if (hrs > 0)
(void)printf("%d hr%s",
hrs, hrs > 1 ? "s" : "");
if (mins > 0 || (days == 0 && hrs == 0))
(void)printf("%d min%s",
mins, mins != 1 ? "s" : "");
}
} else
printf("%d secs", (int)uptime);
}
return 0;
}
```
---
Comments?
=> mailto:
[email protected]?subject=uptm-only-show-system-uptime
Comments intructions
=>
https://si3t.ch/log/_commentaires_.txt