diff --git a/prwtmp/GNUmakefile b/prwtmp/GNUmakefile new file mode 100644 index 0000000..ee1a01c --- /dev/null +++ b/prwtmp/GNUmakefile @@ -0,0 +1,22 @@ +CC = gcc -Wall +INSTALL = /usr/local/bin/install + +prwtmp: + +install: $(ROOT)/usr/local/bin/prwtmp $(ROOT)/usr/local/man/man8/prwtmp.8 + +install_all: + $(MAKE) install ROOT=/nfs/wsrdb + $(MAKE) install ROOT=/nfs/wsrcom + $(MAKE) install ROOT=/nfs/wifosv + $(MAKE) install ROOT=/nfs/ihssv + $(MAKE) install ROOT=/nfs/wsrtest + +$(ROOT)/usr/local/bin/%: % + $(INSTALL) $< $@ + +$(ROOT)/usr/local/man/man8/%.8: %.man + $(INSTALL) $< $@ + +clean: + rm prwtmp diff --git a/prwtmp/prwtmp.c b/prwtmp/prwtmp.c new file mode 100644 index 0000000..b49b0c8 --- /dev/null +++ b/prwtmp/prwtmp.c @@ -0,0 +1,104 @@ +char prwtmp_c_rcs_id[] = + "$Id: prwtmp.c,v 1.1 1997-01-13 14:59:40 hjp Exp $"; +/* + * prwtmp - print wtmp to stdout + * + * $Log: prwtmp.c,v $ + * Revision 1.1 1997-01-13 14:59:40 hjp + * Checked into CVS. + * Added -o and -s options. + * + */ +#include +#include +#include +#include +#include +#include + +#include +#include + +char *cmnd; + +void usage(void) { + fprintf(stderr, "Usage: %s [-o] [-s start] [file]\n", cmnd); + exit(1); +} + + +int main (int argc, char **argv) { + FILE *fp; + struct utmp u; + char *filename = WTMP_FILE; + long off; + int print_offset = 0; + int c; + char *p; + + cmnd = argv[0]; + while ((c = getopt(argc, argv, "s:o")) != EOF) { + switch(c) { + case 's': + off = strtoul(optarg, &p, 0); + if (p == optarg || *p != '\0') usage(); + break; + case 'o': + print_offset = 1; + break; + case '?': + usage(); + default: + assert(0); + } + } + + if (argc > optind) filename = argv[optind]; + + fp = fopen(filename, "rb"); + if (!fp) { + fprintf(stderr, "%s: cannot open %s: %s\n", + cmnd, filename, strerror(errno)); + exit(1); + } + if (fseek(fp, off, SEEK_SET) == -1) { + fprintf(stderr, "%s: cannot seek to %ld on %s: %s\n", + cmnd, off, filename, strerror(errno)); + exit(1); + } + + while (fread(&u, (int)sizeof(u), 1, fp) == 1) { + char tbuf[20]; + + if (print_offset) printf ("%8ld: ", off); + off += sizeof(u); + + strftime(tbuf, (int)sizeof(tbuf), "%Y-%m-%d %H:%M:%S", + localtime(&u.ut_time)); + printf("%s ", tbuf); + printf("%-*.*s ", + (int)sizeof(u.ut_user), + (int)sizeof(u.ut_user), + u.ut_user); + printf("%-*.*s ", + (int)sizeof(u.ut_id), + (int)sizeof(u.ut_id), + u.ut_id); + printf("%-*.*s ", + (int)sizeof(u.ut_line), + (int)sizeof(u.ut_line), + u.ut_line); + printf("%5d ", (int)u.ut_pid); /* PID is typically < 30000 */ + printf("%5d ", (int)u.ut_type); /* short on HP-UX */ + printf("%5d ", (int)u.ut_exit.e_termination); /* short on HP-UX */ + printf("%5d ", (int)u.ut_exit.e_exit); /* short on HP-UX */ + printf("%-*.*s ", + (int)sizeof(u.ut_host), + (int)sizeof(u.ut_host), + u.ut_host); + printf("%08lx", u.ut_addr); + printf("\n"); + + } + return 0; +} diff --git a/prwtmp/prwtmp.man b/prwtmp/prwtmp.man new file mode 100644 index 0000000..0e22576 --- /dev/null +++ b/prwtmp/prwtmp.man @@ -0,0 +1,48 @@ +.\" $Header: /usr/local/src/master/simple/prwtmp/prwtmp.man,v 1.1 1997-01-13 14:59:41 hjp Exp $ +.TH prwtmp 8 +.SH NAME +prwtmp \- print contents of wtmp file +.SH SYNOPSIS +.C prwtmp +.RC [ \-o ] +.RC [ \-s start ] +.RC [ file ] +.SH DESCRIPTION +.C prwtmp +interpretes +.I file +(default is the system wtmp file, normally /etc/wtmp, /var/log/wtmp, or +/var/adm/wtmp) as a +wtmp file and prints one line to stdout for each record. +If the +.B \-o +Option is given, each record is preceded by a decimal byte offset. +If the +.B -s +Option is given, processing starts at the given byte offset instead of +the beginning of the file. +.SH RETURN VALUE +Exit values are: +.RS 3 +.TP 8 +.B \00 +Successful completion. +.PD 0 +.TP +.B >0 +Error condition occurred. +.RE +.PD +.SH FILES +.TP +.B /etc/wtmp +.B /var/adm/wtmp +.B /var/log/wtmp +Default wtmp file (depends on OS). +.SH BUGS +None known. There are a few improvements planned, though: +An option to print the file in reverse (like last(1M), but without +coalescing matching records). Some way to select records or columns. +NLS support would be nice, too. +.SH SEE ALSO +last(1M)