allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc) (12/13/89)
Posting-number: Volume 9, Issue 60 Submitted-by: robert@longs.LANCE.ColoState.Edu (Robert Thompson) Archive-name: rwhoparse Here is a program that you might find useful, people arround here have. It parses the output from rwho and returns some interesting information. -Robert #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of shell archive." # Contents: README Makefile rwhop.n rwhoparse.c # Wrapped by robert@longs.LANCE.ColoState.Edu on Mon Dec 11 21:16:41 1989 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'README' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'README'\" else echo shar: Extracting \"'README'\" \(595 characters\) sed "s/^X//" >'README' <<'END_OF_FILE' rwhop is a program I wrote one bored Sunday night for something to do. I was prompted to post this code for others to use. The main reason for the program is to return the users real name instead of just the login name. If there are any problems, send me mail and I will try to rectify the bug. X This coed is supplied without copyright, do with it what you please. (Tell me of any improvements you have.) I was thinking of making the program search for a host rather than just a user (maybe someday). X Robert CSU - Center forComputer Assisted Engineering X robert@longs.LANCE.ColoState.Edu END_OF_FILE if test 595 -ne `wc -c <'README'`; then echo shar: \"'README'\" unpacked with wrong size! fi # end of 'README' fi if test -f 'Makefile' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'Makefile'\" else echo shar: Extracting \"'Makefile'\" \(469 characters\) sed "s/^X//" >'Makefile' <<'END_OF_FILE' X################################################################# X# X# rwhoparse makefile created 12/10/89 X# X# No copyrights inplied or requested. This code is supplied as is X# have fun using it and report any bugs to: X# X# robert@longs.LANCE.ColoState.edu X# X################################################################# OBJS= rwhoparse.o SRCS= rwhoparse.c X TARGET= rwhop CC= gcc -O -ansi X all: X $(CC) -o $(TARGET) rwhoparse.c X clean: X rm -f *.o $(TARGET) core END_OF_FILE if test 469 -ne `wc -c <'Makefile'`; then echo shar: \"'Makefile'\" unpacked with wrong size! fi # end of 'Makefile' fi if test -f 'rwhop.n' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'rwhop.n'\" else echo shar: Extracting \"'rwhop.n'\" \(1083 characters\) sed "s/^X//" >'rwhop.n' <<'END_OF_FILE' X.\" SCCSID: @(#)rwhop.n 1.0 12/10/89 X.TH rwhop n X.SH NAME rwhop \- rwho(1) output parser X.SH SYNTAX X.B rwhop X[ X.B \-ah X] [\fIusers\fR] X.SH DESCRIPTION The X.PN rwhop command takes the output from rwho(1) via a pipe stream connection. The returned information is the same as that of rwho with the following exceptions: 1) fully qualified host names are truncated to the first level. X2) The users' gecos information is retreived via the getpwnam(3) call. The first field of the gecos information is printed un the heading of 'Real Name' X.SH OPTIONS X.IP \fB\-a\fR 20 Lists all users. Normally, X.PN rwhop omits users who have not typed to the system for an hour or more. If the X.B \-a flag is specified, these users are also listed. X.IP \fB\-h\fR 20 Sorts users by host name. Normally, X.PN rwhop prints its output sorted by user name. If the X.B \-h flag is specified, the results are sorted by host name. X.SH FILES X/usr/spool/rwho/whod.* Information about other machines X.SH SEE ALSO ruptime(1c), rwhod(8c) X.SH AUTHOR Robert D. Thompson - Colorado State University December 10, 1989 END_OF_FILE if test 1083 -ne `wc -c <'rwhop.n'`; then echo shar: \"'rwhop.n'\" unpacked with wrong size! fi # end of 'rwhop.n' fi if test -f 'rwhoparse.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'rwhoparse.c'\" else echo shar: Extracting \"'rwhoparse.c'\" \(1024 characters\) sed "s/^X//" >'rwhoparse.c' <<'END_OF_FILE' X#include <stdio.h> X#include <pwd.h> X#define RWHO "/usr/ucb/rwho " X main(argc,argv) int argc; char *argv[]; X{ X FILE *pipe; X X char real_name[20], inline[80]; X char *user, *host, *time, *gecos, *tty, *strtok(); X X register int i; X X struct passwd *pw; X X argv++; X strcpy(inline,RWHO); X strcat(inline,*argv); X X if ((pipe = popen(inline,"r")) == NULL) X { X fprintf (stderr,"Broken pipe\n"); X exit(-1); X } X printf ("User Real Name Host TTY When Idle\n"); X for (i=0;i<80;i++) printf ("-"); X printf ("\n"); X X while (fgets(inline,80,pipe) != NULL) X { X user = strtok(inline," "); X host = strtok(NULL,":"); X tty = strtok(NULL," "); X time = strtok(NULL,"\n"); X X if ((pw = getpwnam(user)) != NULL) X { X gecos = strtok(pw->pw_gecos,","); X X strncpy(real_name,gecos,20); X real_name[20] = NULL; X X while(time[0] == ' ') time++; X while(host[0] == ' ') host++; X X printf ("%8s %20s %10s %6s %s\n", X user, X real_name, X strtok(host,"."), X tty, X time); X } X } X} END_OF_FILE if test 1024 -ne `wc -c <'rwhoparse.c'`; then echo shar: \"'rwhoparse.c'\" unpacked with wrong size! fi # end of 'rwhoparse.c' fi echo shar: End of shell archive. exit 0