User Status (us) program

espo at bpa.UUCP espo at bpa.UUCP
Fri Jun 17 01:11:11 AEST 1983


	Here's a short program to find out what the user's on your
	system are doing.  It's called 'us' and searches the utmp
	file to see who's logged in and then executes ps -ft with
	a list of terminals.

	Just delete everything down to and including the ***** line
	and run 'sh' on the file.  It will extract the source.  Then 
	cc -O -s us.c -o us and you've got it!



	Have Fun.....

	Bob Esposito......sb6!bpa!espo

NOTE:  It excludes info about the user who is executing the program, since
	he knows what he's doing (I hope).

************************************************************
echo -x us.c
cat > us.c <<'!Funky!Stuff!'
/*      @(#)us.c        4.0     */
/*
 *	[ program ]	us
 *	[ author ]	Bob Esposito
 *
 */

#include <stdio.h>
#include <utmp.h>
struct utmp utp;

char ttylog[100];
char *getlogin();

main(argc, argv)
char **argv;
{
	register char *s;
        register FILE *fi;
	int pid, rtn;

        s = "/etc/utmp";
        if(argc > 1) {
		fprintf(stderr, "Usage: us -- get status of all users\n");
                exit(1);
        }
        if ((fi = fopen(s, "r")) == NULL) {
                fprintf(stderr, "us: cannot open %s\n", s);
                exit(2);
        }

	while (fread((char *)&utp, sizeof(utp), 1, fi) == 1) {
		if(utp.ut_name[0] == '\0')
			continue;	/* vacant slot */
		if(strcmp(getlogin(), utp.ut_name) == 0)
			continue;	/* skip yourself */
		strcat(ttylog, &utp.ut_line[3]);
		strcat(ttylog, ",");
	}
	if((pid = fork()) == 0) {
		execl("/bin/ps", "ps", "-ft", ttylog, 0);

	}while((rtn = wait((int *)0)) != pid);
}
!Funky!Stuff!



More information about the Comp.sources.unix mailing list