diff options
Diffstat (limited to 'usr/src')
-rw-r--r-- | usr/src/cmd/last/last.c | 89 | ||||
-rw-r--r-- | usr/src/man/man1/last.1 | 19 |
2 files changed, 83 insertions, 25 deletions
diff --git a/usr/src/cmd/last/last.c b/usr/src/cmd/last/last.c index 26041d1c1a..0bdf8f0c41 100644 --- a/usr/src/cmd/last/last.c +++ b/usr/src/cmd/last/last.c @@ -20,6 +20,8 @@ * CDDL HEADER END */ /* + * Copyright (c) 2017 Olaf Bohlen + * * Copyright (c) 2013 Gary Mills * * Copyright 2004 Sun Microsystems, Inc. All rights reserved. @@ -77,7 +79,8 @@ #define linehostnameq(a, b, c, d) \ (lineq(a, b)&&hosteq(a+LMAX+1, c)&&nameq(a+LMAX+HMAX+2, d)) -#define USAGE "usage: last [-n number] [-f filename] [-a ] [name | tty] ...\n" +#define USAGE "usage: last [-n number] [-f filename] [-a ] [ -l ] [name |\ + tty] ...\n" /* Beware: These are set in main() to exclude the executable name. */ static char **argv; @@ -116,6 +119,7 @@ main(int ac, char **av) { int i, j; int aflag = 0; + int lflag = 0; /* parameter -l, long format with seconds and years */ int fpos; /* current position in time format buffer */ int chrcnt; /* # of chars formatted by current sprintf */ int bl, wtmp; @@ -210,6 +214,11 @@ main(int ac, char **av) aflag++; break; + /* -l turns on long dates and times */ + case 'l': + lflag++; + break; + default: (void) fprintf(stderr, gettext(USAGE)); exit(1); @@ -299,9 +308,17 @@ next_word: (void) snprintf(hostf, sizeof (hostf), "%-*.*s", hostf_len, hostf_len, bp->ut_host); - fpos = snprintf(timef, sizeof (timef), - "%10.10s %5.5s ", - ct, 11 + ct); + /* write seconds and year if -l specified */ + if (lflag > 0) { + fpos = snprintf(timef, sizeof (timef), + "%10.10s %13.13s ", + ct, 11 + ct); + } else { + fpos = snprintf(timef, sizeof (timef), + "%10.10s %5.5s ", + ct, 11 + ct); + } + if (!lineq(bp->ut_line, "system boot") && !lineq(bp->ut_line, "system down")) { if (otime == 0 && @@ -342,8 +359,13 @@ next_word: if (fpos < sizeof (timef)) { /* timef still has room */ - chrcnt = snprintf(timef + fpos, sizeof (timef) - fpos, - gettext("- %5.5s"), ctime(&otime) + 11); + if (lflag > 0) { + chrcnt = snprintf(timef + fpos, sizeof (timef) - fpos, + gettext("- %8.8s"), ctime(&otime) + 11); + } else { + chrcnt = snprintf(timef + fpos, sizeof (timef) - fpos, + gettext("- %5.5s"), ctime(&otime) + 11); + } fpos += chrcnt; } @@ -353,28 +375,53 @@ next_word: if (fpos < sizeof (timef)) { /* timef still has room */ - (void) snprintf(timef + fpos, sizeof (timef) - fpos, - gettext(" (%5.5s)"), asctime(gmtime(&delta)) + 11); + if (lflag > 0) { + (void) snprintf(timef + fpos, sizeof (timef) - fpos, + gettext(" (%8.8s)"), asctime(gmtime(&delta)) + 11); + } else { + (void) snprintf(timef + fpos, sizeof (timef) - fpos, + gettext(" (%5.5s)"), asctime(gmtime(&delta)) + 11); + } + } } else { if (fpos < sizeof (timef)) { /* timef still has room */ - (void) snprintf(timef + fpos, sizeof (timef) - fpos, - gettext(" (%ld+%5.5s)"), delta / SECDAY, - asctime(gmtime(&delta)) + 11); + if (lflag > 0) { + (void) snprintf(timef + fpos, sizeof (timef) - fpos, + gettext(" (%ld+%8.8s)"), delta / SECDAY, + asctime(gmtime(&delta)) + 11); + } else { + (void) snprintf(timef + fpos, sizeof (timef) - fpos, + gettext(" (%ld+%5.5s)"), delta / SECDAY, + asctime(gmtime(&delta)) + 11); + } } } + } } + if (lflag > 0) { + if (aflag) + (void) printf("%-.*s %-.*s\n", + strlen(timef), timef, + strlen(hostf), hostf); + else + (void) printf( + "%-16.16s %-.*s\n", hostf, + strlen(timef), timef); + } else { + if (aflag) + (void) printf( + "%-35.35s %-.*s\n", timef, + strlen(hostf), hostf); + else + (void) printf( + "%-16.16s %-.35s\n", hostf, + timef); } - if (aflag) - (void) printf("%-35.35s %-.*s\n", - timef, strlen(hostf), hostf); - else - (void) printf("%-16.16s %-.35s\n", - hostf, timef); (void) fflush(stdout); if (++outrec >= maxrec) exit(0); @@ -399,7 +446,13 @@ next_word: } } ct = ctime(&buf[0].ut_xtime); - (void) printf(gettext("\nwtmp begins %10.10s %5.5s \n"), ct, ct + 11); + if (lflag > 0) { + (void) printf(gettext("\nwtmp begins %10.10s %13.13s \n"), ct, + ct + 11); + } else { + (void) printf(gettext("\nwtmp begins %10.10s %5.5s \n"), ct, + ct + 11); + } /* free() called to prevent lint warning about names */ free(names); diff --git a/usr/src/man/man1/last.1 b/usr/src/man/man1/last.1 index 1fe2b015ad..c2f1a09e4a 100644 --- a/usr/src/man/man1/last.1 +++ b/usr/src/man/man1/last.1 @@ -1,21 +1,21 @@ '\" te .\" Copyright 1989 AT&T .\" Copyright (c) 2004 Sun Microsystems, Inc. All Rights Reserved. +.\" Copyright (c) 2017 Olaf Bohlen .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] -.TH LAST 1 "Jul 24, 2004" +.TH LAST 1 "Apr 12, 2017" .SH NAME last \- display login and logout information about users and terminals .SH SYNOPSIS .LP .nf -\fBlast\fR [\fB-a\fR] [\fB-n\fR \fInumber\fR | \fB-number\fR] [\fB-f\fR \fIfilename\fR] +\fBlast\fR [\fB-a\fR] [\fB-l\fR] [\fB-n\fR \fInumber\fR | \fB-number\fR] [\fB-f\fR \fIfilename\fR] [\fIname\fR | \fItty\fR]... .fi .SH DESCRIPTION -.sp .LP The \fBlast\fR command looks in the \fB/var/adm/wtmpx\fR file, which records all logins and logouts, for information about a user, a terminal, or any group @@ -55,7 +55,6 @@ If \fBlast\fR is interrupted, it indicates how far the search has progressed in CTRL\(mi\e), \fBlast\fR indicates how far the search has progressed, and then continues the search. .SH OPTIONS -.sp .LP The following options are supported: .sp @@ -70,6 +69,15 @@ Displays the hostname in the last column. .sp .ne 2 .na +\fB\fB-l\fR\fR +.ad +.RS 25n +Displays timestamps with seconds and years. +.RE + +.sp +.ne 2 +.na \fB\fB-f\fR\fI filename\fR\fR .ad .RS 25n @@ -89,12 +97,10 @@ transition tool only and is removed in future releases. .RE .SH ENVIRONMENT VARIABLES -.sp .LP Date and time format is based on locale specified by the \fBLC_ALL\fR, \fBLC_TIME\fR, or \fBLANG\fR environments, in that order of priority. .SH FILES -.sp .ne 2 .na \fB\fB/var/adm/wtmpx\fR\fR @@ -104,6 +110,5 @@ accounting file .RE .SH SEE ALSO -.sp .LP \fButmpx\fR(4), \fBattributes\fR(5) |