Marc Balmer wrote:

> hmm, why are people so proud of their uptimes when it only show they
> don't care for their systems?
>


Below is a patch which adds an -i flag to 'uptime' converting an uptime
period to a size in inches:

evilkittens:w {160} ./uptime
11:13AM  up 24 days, 16:42, 1 user, load averages: 0.14, 0.15, 0.13
evilkittens:w {161} ./uptime -i
11:13AM  up 3 inches, 1 user, load averages: 0.14, 0.15, 0.13
evilkittens:w {162}

As you see, I better let my system run a bit longer :(


--- /usr/src/usr.bin/w/w.c      Tue Jul 19 23:19:08 2005
+++ w.c Wed Jan 17 11:16:15 2007
@@ -92,6 +92,7 @@
 int    header = 1;     /* true if -h flag: don't print heading */
 int    nflag = 1;      /* true if -n flag: don't convert addrs */
 int    sortidle; /* sort bu idle time */
+int    inches = 0;     /* compute len of uptime in inches */
 char         *sel_user;  /* login of particular user selected */
 char   domain[MAXHOSTNAMELEN];
 
@@ -137,7 +138,7 @@
   p = "hiflM:N:asuw";
  } else if (!strcmp(p, "uptime")) {
   wcmd = 0;
-  p = "";
+  p = "i";
  } else
   errx(1,
    "this program should be invoked only as \"w\" or \"uptime\"");
@@ -149,7 +150,10 @@
    header = 0;
    break;
   case 'i':
-   sortidle = 1;
+   if (wcmd == 1)
+      sortidle = 1;
+   else
+      inches = 1;
    break;
   case 'M':
    header = 0;
@@ -402,29 +406,36 @@
  size = sizeof(boottime);
  if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1) {
   uptime = now - boottime.tv_sec;
-  if (uptime > 59) {
-   uptime += 30;
-   days = uptime / SECSPERDAY;
-   uptime %= SECSPERDAY;
-   hrs = uptime / SECSPERHOUR;
-   uptime %= SECSPERHOUR;
-   mins = uptime / SECSPERMIN;
+  if (inches == 1) {
+   inches = uptime / (60*60*24*7);
    (void)printf(" up");
-   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,", uptime);
+   (void)printf(" %d inch%s,", inches, inches > 1 ? "es": "");
+  }
+  else {
+   if (uptime > 59) {
+      uptime += 30;
+      days = uptime / SECSPERDAY;
+      uptime %= SECSPERDAY;
+      hrs = uptime / SECSPERHOUR;
+      uptime %= SECSPERHOUR;
+      mins = uptime / SECSPERMIN;
+      (void)printf(" up");
+      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,", uptime);
+  }
  }
 
  /* Print number of users logged in to system */

Reply via email to