ru - list remote users
majka at ubc-cs.UUCP
majka at ubc-cs.UUCP
Tue Dec 30 10:36:10 AEST 1986
Here is a little program which filters the output of rwho to make a nice list
of users on a local network. See the README file for an example of the output.
Cut on the dotted line and feed to "sh".
---
Marc Majka (VE7FIZ) - UBC Laboratory for Computational Vision
- - - CUT - - - CUT - - - CUT - - - CUT - - - CUT - - - CUT - - - CUT - - -
#/bin/sh
#
# shell archive - extract with /bin/sh
#
echo extracting file README
sed 's/^X//' > README <<'!FUNKY!STUFF!'
XThis package contains a filter for listing the users on a local area network.
XThe filter program, "ruf", reads the output of the "rwho" command, and writes
Xa list of users on each local machine in a format similar to "users".
X
XThe shell command "ru" calls rho and pipes the output on to ruf. You should
Xedit ru to change the FILTER variable to point to ruf.
X
X
XExample output of rwho:
X
Xbashful mickey:tty01 Dec 29 13:45
Xdoc daffy:console Dec 29 13:45
Xdoc goofy:ttyp0 Dec 29 14:53 :07
Xdopey mickey:console Dec 29 13:45
Xdopey mickey:ttyp0 Dec 29 13:45
Xdopey mickey:ttyp1 Dec 29 15:51
Xdopey mickey:ttyp2 Dec 29 15:54
Xgrumpy mickey:tty00 Dec 29 13:48
Xgrumpy mickey:ttyp3 Dec 29 13:48
Xgrumpy porky:ttyp0 Dec 29 14:01
Xgrumpy porky:ttyp1 Dec 29 14:02
Xhappy goofy:tty08 Dec 29 14:41 :01
Xhappy porky:ttyh2 Dec 29 14:45
Xsleepy goofy:tty07 Dec 29 12:31
Xsneezy goofy:tty09 Dec 29 15:20
X
X
XExample output of ru:
X
Xmickey (7)
X bashful dopey(4) grumpy(2)
Xdaffy (1)
X doc
Xgoofy (4)
X doc happy sleepy sneezy
Xporky (3)
X grumpy(2) happy
X
X
XExample output of ru -t:
X
Xmickey (7)
X bashful:01 dopey(4):console,p0,p1,p2 grumpy(2):00,p3
Xdaffy (1)
X doc:console
Xgoofy (4)
X doc:p0 happy:08 sleepy:07 sneezy:09
Xporky (3)
X grumpy(2):p0,p1 happy:h2
!FUNKY!STUFF!
echo extracting file Makefile
sed 's/^X//' > Makefile <<'!FUNKY!STUFF!'
X# makefile for ru
X
Xru: ruf
X
Xruf: ruf.c
X cc -o ruf ruf.c
!FUNKY!STUFF!
echo extracting file ru.1
sed 's/^X//' > ru.1 <<'!FUNKY!STUFF!'
X.TH RU 1
X.SH NAME
Xru - list of users on local network
X.SH SYNOPSIS
Xru [-t]
X.SH DESCRIPTION
X.I ru
Xis a shell script which pipes the output of
X.I rwho(1)
Xthrough the filter
X.I ruf.
XThe filter output is a list of local hosts followed by the users logged in on
Xthose hosts. The format is meant to be similar to the output of
X.I users(1).
XThe
X.B \-t
Xoption causes
X.I ru
Xto print the user's terminal after their name.
X.SH AUTHOR
XMarc Majka
!FUNKY!STUFF!
echo extracting file ru
sed 's/^X//' > ru <<'!FUNKY!STUFF!'
XFILTER=ruf
Xrwho -a | $FILTER $*
!FUNKY!STUFF!
echo extracting file ruf.c
sed 's/^X//' > ruf.c <<'!FUNKY!STUFF!'
X/*************************************************************/
X/* */
X/* Copyright (c) 1986 Marc S. Majka */
X/* */
X/* Permission is hereby granted to copy all or any part of */
X/* this program for free distribution. The author's name */
X/* and this copyright notice must be included in any copy. */
X/* */
X/*************************************************************/
X
X#include <stdio.h>
X#define ASIZE 256
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X char line[ASIZE], *host[ASIZE], *user[ASIZE], *tty[ASIZE];
X char ustr[64], htstr[64], hstr[64], tstr[64], *malloc();
X int nhost, nuser, nhuser[ASIZE], uhost[ASIZE], huser[ASIZE];
X int i, j, x, nh, ptty, debug, nlog, logs[ASIZE];
X
X ptty = 0;
X debug = 0;
X
X for (i = 1; i < argc; i++) {
X if (argv[i][0] == '-') {
X switch (argv[i][1]) {
X case 't': ptty = 1; break;
X case 'd': debug = 1; break; /* for hacking */
X default: break;
X }
X }
X }
X
X nhost = 0;
X nuser = 0;
X for (i = 0; i < ASIZE; i++) {
X nhuser[i] = 0;
X uhost[i] = -1;
X }
X
X /* read lines from (we hope) rwho */
X while (EOF != scanf("%[^\n]%*c",line)) {
X
X /* get user and host:tty */
X sscanf(line,"%s%s",ustr,htstr);
X
X /* separate host and tty */
X for (i = 0; htstr[i] != ':'; i++) hstr[i] = htstr[i];
X hstr[i] = '\0';
X i++;
X
X /* knock off the "tty" part for brevity */
X if (!strncmp(htstr+i,"tty",3)) i += 3;
X strcpy(tstr,htstr+i);
X
X /* look through the host name list for this host */
X x = -1;
X for (i = 0; i < nhost; i++) if (!strcmp(host[i],hstr)) x = i;
X
X /* not found: put the new host on the list */
X if (x < 0) {
X host[nhost] = malloc(strlen(hstr) + 1);
X strcpy(host[nhost],hstr);
X x = nhost;
X nhost++;
X }
X
X /* save the tty, user name and host number for the user */
X tty[nuser] = malloc(strlen(tstr) + 1);
X strcpy(tty[nuser],tstr);
X user[nuser] = malloc(strlen(ustr) + 1);
X strcpy(user[nuser],ustr);
X uhost[nuser] = x;
X nuser++;
X
X /* count number of users for this host */
X nhuser[x]++;
X }
X
X /* for each host ... */
X for (x = 0; x < nhost; x++) {
X
X /* collect a list of the users for this host (x) */
X nh = 0;
X for (i = 0; i < nuser; i++) if (uhost[i] == x) huser[nh++] = i;
X
X /* print host name and number of users */
X printf("%s (%d)\n ",host[x],nh);
X
X /* for each user ... */
X for (i = 0; i < nh; i++) {
X
X /* count the number of logins for this user (i) */
X if (huser[i] >= 0) {
X nlog = 1;
X logs[0] = huser[i];
X
X /* look through the rest of the list for more logins */
X for (j = i+1; j < nh; j++) {
X if (huser[j] >= 0 && !strcmp(user[huser[i]],user[huser[j]])) {
X logs[nlog++] = huser[j];
X huser[j] = -1;
X }
X }
X
X /* print user name and number of logins */
X printf(" %s",user[huser[i]]);
X if (nlog > 1) printf("(%d)",nlog);
X
X /* print out terminals */
X if (ptty) {
X printf(":%s",tty[logs[0]]);
X for (j = 1; j < nlog; j++) printf(",%s",tty[logs[j]]);
X }
X }
X }
X
X printf("\n");
X }
X
X exit(0);
X}
!FUNKY!STUFF!
echo Done\!
exit 0
More information about the Comp.sources.unix
mailing list