1.\" $NetBSD: utmp.5,v 1.5 1994/11/30 19:31:35 jtc Exp $ 2.\" 3.\" Copyright (c) 1980, 1991, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. All advertising materials mentioning features or use of this software 15.\" must display the following acknowledgement: 16.\" This product includes software developed by the University of 17.\" California, Berkeley and its contributors. 18.\" 4. Neither the name of the University nor the names of its contributors 19.\" may be used to endorse or promote products derived from this software 20.\" without specific prior written permission. 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32.\" SUCH DAMAGE. 33.\" 34.\" @(#)utmp.5 8.2 (Berkeley) 3/17/94 35.\" 36.Dd March 17, 1994 37.Dt UTMP 5 38.Os BSD 4 39.Sh NAME 40.Nm utmp , 41.Nm wtmp , 42.Nm lastlog 43.Nd login records 44.Sh SYNOPSIS 45.Fd #include <utmp.h> 46.Sh DESCRIPTION 47The file 48.Aq Pa utmp.h 49declares the structures used to record information about current 50users in the file 51.Nm utmp , 52logins and logouts in the file 53.Nm wtmp , 54and last logins in the file 55.Nm lastlog . 56The time stamps of date changes, shutdowns and reboots are also logged in 57the 58.Nm wtmp 59file. 60.Pp 61These files can grow rapidly on busy systems, daily or weekly rotation 62is recommended. 63If any of these files do not exist, it is not created. 64These 65files must be created manually and are normally maintained in either the script 66.Pa /etc/daily 67or the script 68.Pa /etc/weekly . 69(See 70.Xr cron 8 . ) 71.Bd -literal -offset indent 72#define _PATH_UTMP "/var/run/utmp" 73#define _PATH_WTMP "/var/log/wtmp" 74#define _PATH_LASTLOG "/var/log/lastlog" 75 76#define UT_NAMESIZE 8 77#define UT_LINESIZE 8 78#define UT_HOSTSIZE 16 79 80struct lastlog { 81 time_t ll_time; 82 char ll_line[UT_LINESIZE]; 83 char ll_host[UT_HOSTSIZE]; 84}; 85 86struct utmp { 87 char ut_line[UT_LINESIZE]; 88 char ut_name[UT_NAMESIZE]; 89 char ut_host[UT_HOSTSIZE]; 90 time_t ut_time; 91}; 92.Ed 93.Pp 94Each time a user logs in, the 95.Xr login 96program looks up the user's 97.Tn UID 98in the file 99.Nm lastlog. 100If it is found, the timestamp of the last time the user logged 101in, the terminal line and the hostname 102are written to the standard output. (Providing the login is not 103.Em quiet , 104see 105.Xr login 1 . ) 106The 107.Xr login 108program then records the new login time in the file 109.Nm lastlog . 110.Pp 111After the new 112.Fa lastlog 113record is written , 114.\" the 115.\" .Xr libutil 3 116.\" routine 117the file 118.Nm utmp 119is opened and the 120.Fa utmp 121record for the user inserted. 122This record remains there until 123the user logs out at which time it is deleted. 124The 125.Nm utmp 126file is used by the programs 127.Xr rwho 1 , 128.Xr users 1 , 129.Xr w 1 , 130and 131.Xr who 1 . 132.Pp 133Next, the 134.Xr login 135program opens the file 136.Nm wtmp , 137and appends the user's 138.Fa utmp 139record. 140The same 141.Fa utmp 142record, with an updated time stamp is later appended 143to the file when the user logs out. (See 144.Xr init 8 . ) 145The 146.Nm wtmp 147file is used by the programs 148.Xr last 1 149and 150.Xr ac 8 . 151.Pp 152In the event of a date change, a shutdown or reboot, the 153following items are logged in the 154.Nm wtmp 155file. 156.Pp 157.Bl -tag -width shutdownxx -compact 158.It Li reboot 159.It Li shutdown 160A system reboot or shutdown has been initiated. 161The character 162.Ql \&~ 163is placed in the field 164.Fa ut_line , 165and 166.Li reboot 167or 168.Li shutdown 169in the field 170.Fa ut_name . 171(See 172.Xr shutdown 8 173and 174.Xr reboot 8 . ) 175.Pp 176.It Li date 177The system time has been manually or automatically updated. 178(See 179.Xr date 1 . ) 180The command name 181.Xr date 182is recorded in the field 183.Fa ut_name . 184In the field 185.Fa ut_line , 186the character 187.Ql \\*(Ba 188indicates the time prior to the change, and the character 189.Ql \&{ 190indicates the new time. 191.El 192.Sh FILES 193.Bl -tag -width /var/log/lastlog -compact 194.It Pa /var/run/utmp 195The 196.Nm utmp file. 197.It Pa /var/log/wtmp 198The 199.Nm wtmp file. 200.It Pa /var/log/lastlog 201The 202.Nm lastlog file. 203.El 204.Sh SEE ALSO 205.Xr last 1 , 206.Xr login 1 , 207.Xr who 1 , 208.Xr ac 8 , 209.Xr init 8 210.Sh HISTORY 211A 212.Nm utmp 213and 214.Nm wtmp 215file format appeared in 216.At v6 . 217The 218.Nm lastlog 219file format appeared in 220.Bx 3.0 . 221