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