1*ec247841Ssevan.\" $NetBSD: utmp.5,v 1.18 2019/09/09 00:21:03 sevan Exp $ 2b5930afcSjtc.\" 3b5930afcSjtc.\" Copyright (c) 1980, 1991, 1993 4b5930afcSjtc.\" The Regents of the University of California. All rights reserved. 561f28255Scgd.\" 661f28255Scgd.\" Redistribution and use in source and binary forms, with or without 761f28255Scgd.\" modification, are permitted provided that the following conditions 861f28255Scgd.\" are met: 961f28255Scgd.\" 1. Redistributions of source code must retain the above copyright 1061f28255Scgd.\" notice, this list of conditions and the following disclaimer. 1161f28255Scgd.\" 2. Redistributions in binary form must reproduce the above copyright 1261f28255Scgd.\" notice, this list of conditions and the following disclaimer in the 1361f28255Scgd.\" documentation and/or other materials provided with the distribution. 14075022b3Sagc.\" 3. Neither the name of the University nor the names of its contributors 1561f28255Scgd.\" may be used to endorse or promote products derived from this software 1661f28255Scgd.\" without specific prior written permission. 1761f28255Scgd.\" 1861f28255Scgd.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1961f28255Scgd.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2061f28255Scgd.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2161f28255Scgd.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2261f28255Scgd.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2361f28255Scgd.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2461f28255Scgd.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2561f28255Scgd.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2661f28255Scgd.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2761f28255Scgd.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2861f28255Scgd.\" SUCH DAMAGE. 2961f28255Scgd.\" 30b5930afcSjtc.\" @(#)utmp.5 8.2 (Berkeley) 3/17/94 3161f28255Scgd.\" 32*ec247841Ssevan.Dd September 9, 2019 3361f28255Scgd.Dt UTMP 5 347a1aea16Sgarbled.Os 3561f28255Scgd.Sh NAME 3661f28255Scgd.Nm utmp , 3761f28255Scgd.Nm wtmp , 3861f28255Scgd.Nm lastlog 3961f28255Scgd.Nd login records 4061f28255Scgd.Sh SYNOPSIS 41472351e1Swiz.In utmp.h 4261f28255Scgd.Sh DESCRIPTION 4361f28255ScgdThe file 445e015e5eSjoerg.In utmp.h 4561f28255Scgddeclares the structures used to record information about current 4661f28255Scgdusers in the file 4761f28255Scgd.Nm utmp , 4861f28255Scgdlogins and logouts in the file 4961f28255Scgd.Nm wtmp , 5061f28255Scgdand last logins in the file 5161f28255Scgd.Nm lastlog . 5261f28255ScgdThe time stamps of date changes, shutdowns and reboots are also logged in 5361f28255Scgdthe 5461f28255Scgd.Nm wtmp 5561f28255Scgdfile. 5661f28255Scgd.Pp 5724f9e74aSmycroftThe 5824f9e74aSmycroft.Nm wtmp 5924f9e74aSmycroftfile can grow rapidly on busy systems, and is normally rotated with 6024f9e74aSmycroft.Xr newsyslog 8 . 6124f9e74aSmycroft.Pp 6224f9e74aSmycroftThese files must be created manually; 6324f9e74aSmycroftif they do not exist, they are not created automatically. 6461f28255Scgd.Bd -literal -offset indent 6561f28255Scgd#define _PATH_UTMP "/var/run/utmp" 6661f28255Scgd#define _PATH_WTMP "/var/log/wtmp" 6761f28255Scgd#define _PATH_LASTLOG "/var/log/lastlog" 6861f28255Scgd 6961f28255Scgd#define UT_NAMESIZE 8 7061f28255Scgd#define UT_LINESIZE 8 7161f28255Scgd#define UT_HOSTSIZE 16 7261f28255Scgd 7361f28255Scgdstruct lastlog { 7461f28255Scgd time_t ll_time; 7561f28255Scgd char ll_line[UT_LINESIZE]; 7661f28255Scgd char ll_host[UT_HOSTSIZE]; 7761f28255Scgd}; 7861f28255Scgd 7961f28255Scgdstruct utmp { 8061f28255Scgd char ut_line[UT_LINESIZE]; 8161f28255Scgd char ut_name[UT_NAMESIZE]; 8261f28255Scgd char ut_host[UT_HOSTSIZE]; 83a9115883Scgd time_t ut_time; 8461f28255Scgd}; 8561f28255Scgd.Ed 8661f28255Scgd.Pp 8761f28255ScgdEach time a user logs in, the 88fa72f5deSfair.Xr login 1 8961f28255Scgdprogram looks up the user's 9061f28255Scgd.Tn UID 9161f28255Scgdin the file 9261f28255Scgd.Nm lastlog . 9361f28255ScgdIf it is found, the timestamp of the last time the user logged 9461f28255Scgdin, the terminal line and the hostname 95fa72f5deSfairare written to the standard output, providing the login is not set 96fa72f5deSfair.Em quiet ; 9761f28255Scgdsee 98fa72f5deSfair.Xr login 1 . 9961f28255ScgdThe 100fa72f5deSfair.Xr login 1 10161f28255Scgdprogram then records the new login time in the file 10261f28255Scgd.Nm lastlog . 10361f28255Scgd.Pp 10461f28255ScgdAfter the new 10561f28255Scgd.Fa lastlog 10661f28255Scgdrecord is written, 10761f28255Scgd.\" the 10861f28255Scgd.\" .Xr libutil 3 10961f28255Scgd.\" routine 11061f28255Scgdthe file 11161f28255Scgd.Nm utmp 11261f28255Scgdis opened and the 11361f28255Scgd.Fa utmp 11461f28255Scgdrecord for the user inserted. 11561f28255ScgdThis record remains there until 116579f2fb4Slukemthe user logs out at which time it is deleted (by clearing 117579f2fb4Slukemthe user and host fields, and updating the timestamp field). 11861f28255ScgdThe 11961f28255Scgd.Nm utmp 12061f28255Scgdfile is used by the programs 12161f28255Scgd.Xr rwho 1 , 12261f28255Scgd.Xr users 1 , 12361f28255Scgd.Xr w 1 , 12461f28255Scgdand 12561f28255Scgd.Xr who 1 . 12661f28255Scgd.Pp 12761f28255ScgdNext, the 128fa72f5deSfair.Xr login 1 12961f28255Scgdprogram opens the file 13061f28255Scgd.Nm wtmp , 13161f28255Scgdand appends the user's 13261f28255Scgd.Fa utmp 13361f28255Scgdrecord. 134579f2fb4SlukemWhen the user logs out, a 13561f28255Scgd.Fa utmp 136579f2fb4Slukemrecord with the tty line, an updated time stamp, and cleared user and host 137fa72f5deSfairfields is appended to the file by 138fa72f5deSfair.Xr init 8 . 13961f28255ScgdThe 14061f28255Scgd.Nm wtmp 14161f28255Scgdfile is used by the programs 14261f28255Scgd.Xr last 1 14361f28255Scgdand 14461f28255Scgd.Xr ac 8 . 14561f28255Scgd.Pp 14661f28255ScgdIn the event of a date change, a shutdown or reboot, the 14761f28255Scgdfollowing items are logged in the 14861f28255Scgd.Nm wtmp 14961f28255Scgdfile. 15061f28255Scgd.Pp 15161f28255Scgd.Bl -tag -width shutdownxx -compact 15261f28255Scgd.It Li reboot 15361f28255Scgd.It Li shutdown 15461f28255ScgdA system reboot or shutdown has been initiated. 15561f28255ScgdThe character 15661f28255Scgd.Ql \&~ 15761f28255Scgdis placed in the field 15861f28255Scgd.Fa ut_line , 15961f28255Scgdand 16061f28255Scgd.Li reboot 16161f28255Scgdor 16261f28255Scgd.Li shutdown 16361f28255Scgdin the field 164fa72f5deSfair.Fa ut_name 165fa72f5deSfair(see 16661f28255Scgd.Xr shutdown 8 16761f28255Scgdand 168fa72f5deSfair.Xr reboot 8 ) . 16961f28255Scgd.Pp 17061f28255Scgd.It Li date 171fa72f5deSfairThe system time has been manually or automatically updated by 172fa72f5deSfair.Xr date 1 . 17361f28255ScgdThe command name 174fa72f5deSfair.Em date 17561f28255Scgdis recorded in the field 17661f28255Scgd.Fa ut_name . 17761f28255ScgdIn the field 17861f28255Scgd.Fa ut_line , 17961f28255Scgdthe character 18061f28255Scgd.Ql \\*(Ba 18144059420Scgdindicates the time prior to the change, and the character 18244059420Scgd.Ql \&{ 18361f28255Scgdindicates the new time. 18461f28255Scgd.El 18561f28255Scgd.Sh FILES 18661f28255Scgd.Bl -tag -width /var/log/lastlog -compact 18761f28255Scgd.It Pa /var/run/utmp 18861f28255ScgdThe 189579f2fb4Slukem.Nm utmp 190579f2fb4Slukemfile. 19161f28255Scgd.It Pa /var/log/wtmp 19261f28255ScgdThe 193579f2fb4Slukem.Nm wtmp 194579f2fb4Slukemfile. 19561f28255Scgd.It Pa /var/log/lastlog 19661f28255ScgdThe 197579f2fb4Slukem.Nm lastlog 198579f2fb4Slukemfile. 19961f28255Scgd.El 20061f28255Scgd.Sh SEE ALSO 20161f28255Scgd.Xr last 1 , 20261f28255Scgd.Xr login 1 , 20386395f06Ssalo.Xr w 1 , 20461f28255Scgd.Xr who 1 , 20596c09cbbShubertf.Xr utmpx 5 , 20661f28255Scgd.Xr ac 8 , 20724f9e74aSmycroft.Xr init 8 , 20886395f06Ssalo.Xr lastlogin 8 , 20924f9e74aSmycroft.Xr newsyslog 8 21061f28255Scgd.Sh HISTORY 21161f28255ScgdA 21261f28255Scgd.Nm utmp 2133402eb4fSsevanfile format appeared in 2143402eb4fSsevan.At v1 . 2153402eb4fSsevanThe 21661f28255Scgd.Nm wtmp 21761f28255Scgdfile format appeared in 218*ec247841Ssevan.At v2 . 21961f28255ScgdThe 22061f28255Scgd.Nm lastlog 22161f28255Scgdfile format appeared in 22261f28255Scgd.Bx 3.0 . 223