changeset 630:03f18afb4b44

Add w command by Gaurang Shastri.
author Rob Landley <rob@landley.net>
date Wed, 18 Jul 2012 20:21:50 -0500
parents 225262d6e6c7
children 7c1a825f5afb
files toys/w.c
diffstat 1 files changed, 47 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/toys/w.c	Wed Jul 18 20:21:50 2012 -0500
@@ -0,0 +1,47 @@
+/* vi: set sw=4 ts=4:
+ *
+ * w.c - shows logged in users
+ *
+ * Copyright 2012 Gaurang Shastri <gmshastri@gmail.com>
+ *
+ * Not in SUSv4.
+
+USE_W(NEWTOY(w, NULL, TOYFLAG_USR|TOYFLAG_BIN))
+
+config W
+	bool "w"
+	default y
+	help
+	  usage: w 
+
+	  Show who is logged on and since how long they logged in.
+
+*/
+
+#include "toys.h"
+
+void w_main(void)
+{
+    struct utmpx *x;
+    time_t time_val;
+    xprintf("USER     TTY             LOGIN@              FROM");
+    setutxent();
+    x=getutxent();
+    while(x!=NULL) {
+        if(x->ut_type==7) {
+	    xprintf("\n");
+            xprintf("%-9.8s",x->ut_user);
+            xprintf("%-9.8s",x->ut_line);
+
+	    xprintf(" ");
+	    time_val = (x->ut_tv.tv_sec);
+	    xprintf("%-4.24s",ctime(&time_val));
+	    
+            xprintf(" (");
+            xprintf("%-1.12s",x->ut_host);
+            xprintf(")");
+        }
+    x=getutxent();
+    }
+    xprintf("\n");
+}