home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume9 / rwhoparse / rwhoparse.c < prev   
Encoding:
C/C++ Source or Header  |  1989-12-12  |  1.0 KB  |  58 lines

  1. #include <stdio.h>
  2. #include <pwd.h>
  3. #define RWHO "/usr/ucb/rwho "
  4.  
  5. main(argc,argv)
  6. int    argc;
  7. char    *argv[];
  8. {
  9.     FILE    *pipe;
  10.  
  11.     char    real_name[20], inline[80];
  12.     char    *user, *host, *time, *gecos, *tty, *strtok();
  13.  
  14.     register int i;
  15.  
  16.     struct    passwd    *pw;
  17.  
  18.     argv++;
  19.     strcpy(inline,RWHO);
  20.     strcat(inline,*argv);
  21.  
  22.     if ((pipe = popen(inline,"r")) == NULL)
  23.         {
  24.         fprintf (stderr,"Broken pipe\n");
  25.         exit(-1);
  26.         }
  27.     
  28. printf ("User                 Real Name        Host   TTY    When         Idle\n");
  29.     for (i=0;i<80;i++) printf ("-");
  30.     printf ("\n");
  31.  
  32.     while (fgets(inline,80,pipe) != NULL)
  33.         {
  34.         user = strtok(inline," ");
  35.         host = strtok(NULL,":");
  36.         tty = strtok(NULL," ");
  37.         time = strtok(NULL,"\n");
  38.  
  39.         if ((pw = getpwnam(user)) != NULL)
  40.             {
  41.             gecos = strtok(pw->pw_gecos,",");
  42.             
  43.             strncpy(real_name,gecos,20);
  44.             real_name[20] = NULL;
  45.             
  46.             while(time[0] == ' ') time++;
  47.             while(host[0] == ' ') host++;
  48.             
  49.             printf ("%8s  %20s  %10s  %6s  %s\n",
  50.                 user,
  51.                 real_name,
  52.                 strtok(host,"."),
  53.                 tty,
  54.                 time);
  55.             }
  56.         }
  57. }
  58.