Technical article 100737

I want to know what the /etc/utmp and /etc/wtmp files contain.

OpenServer 6.0.0OpenServer 5.0.0OpenServer 5.0.2OpenServer 5.0.4OpenServer 5.0.5OpenServer 5.0.6OpenServer 5.0.7UnixWare 7.0.0UnixWare 7.0.1UnixWare 7.1.0UnixWare 7.1.1UnixWare 7.1.2UnixWare 7.1.3UnixWare 7.1.4Open UNIX 8

Written · Last revised

Problem

I want to view the contents of the /etc/utmp and /etc/wtmp files.

Solution

The following program will print the most useful sections of these files in a readable format.

----------------------------------<cut here>----------------------------------
/*
 * Program to print most useful bits of the utmp and wtmp files.
 *
 * Compile with "cc pruwtmp.c".
 *
 */
#include <sys/types.h>
#include <utmp.h>
#include <time.h>
#include <stdio.h>
char *ut_strings[10] = {
        "EMPTY",
        "RUN_LVL",
        "BOOT_TIME",
        "OLD_TIME",
        "NEW_TIME",
        "INIT_PROCESS",
        "LOGIN_PROCESS",
        "USER_PROCESS",
        "DEAD_PROCESS",
        "ACCOUNTING" };
void do_print( file )
char        *file;
{
        struct utmp        *entry;
        char                timestamp[25];
utmpname( file );
setutent();
        printf(
"User     Id   Device Name  PID    Entry Type       Timestamp\n"
        );
        printf(
"-------- ---- ------------ ------ ---------------- ------------------------\n"
        );
while ( (entry = getutent()) != NULL ){
printf( "%8.8s %4.4s %12.12s %6d %2d ",
                entry->ut_user,
                entry->ut_id,
                entry->ut_line,
                entry->ut_pid,
                entry->ut_type );
if ( entry->ut_type >= 0 && entry->ut_type <= 10 )
        printf( "%13.13s ", ut_strings[entry->ut_type] );
else
        printf( "%13.13s ", "(not defined)" );
strftime( timestamp, sizeof( timestamp ),
                "%a %b %d %X %Y",
                localtime( &entry->ut_time ) );
printf( "%24.24s\n",
                timestamp );
}
        endutent();
}

main() { printf( "Contents of the file %s:\n\n", UTMP_FILE ); do_print( UTMP_FILE ); printf( "\n\nContents of the file %s:\n\n", WTMP_FILE ); do_print( WTMP_FILE ); } ----------------------------------<cut here>----------------------------------

Then compile with:
# cc <file>.c -o who_check

This TA assumes that there is a C Compiler installed.

From the Xinuos technical article database, record 100737. Reproduced with permission. The original is at www.sco.com/ta/100737, which is reachable but blocked from search engines.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.