mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-14 20:37:06 +00:00
Reviewed by: Peter Hawkins <thepish@FreeBSD.org>
Add s and w flags to show duration in or with seconds.
This commit is contained in:
parent
0f78c7a7ea
commit
e72acbba84
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=36434
|
@ -42,7 +42,9 @@
|
|||
.Op Fl Ns Ar n
|
||||
.Op Fl f Ar file
|
||||
.Op Fl h Ar host
|
||||
.Op Fl s
|
||||
.Op Fl t Ar tty
|
||||
.Op Fl w
|
||||
.Op user ...
|
||||
.Sh DESCRIPTION
|
||||
.Nm Last
|
||||
|
@ -60,16 +62,22 @@ a crash or shutdown,
|
|||
will so indicate.
|
||||
.Pp
|
||||
.Bl -tag -width indent-two
|
||||
.It Fl Ar n
|
||||
Limits the report to
|
||||
.Ar n
|
||||
lines.
|
||||
.It Fl f Ar file
|
||||
.Nm Last
|
||||
reads the file
|
||||
.Ar file
|
||||
instead of the default,
|
||||
.Pa /var/log/wtmp .
|
||||
.It Fl Ar n
|
||||
Limits the report to
|
||||
.Ar n
|
||||
lines.
|
||||
.It Fl h Ar host
|
||||
.Ar Host
|
||||
names may be names or internet numbers.
|
||||
.It Fl s
|
||||
Report the duration of the login session in seconds, instead of the
|
||||
default days, hours and minutes.
|
||||
.It Fl t Ar tty
|
||||
Specify the
|
||||
.Ar tty .
|
||||
|
@ -78,9 +86,9 @@ Tty names may be given fully or abbreviated, for example,
|
|||
is
|
||||
equivalent to
|
||||
.Dq Li "last -t tty03" .
|
||||
.It Fl h Ar host
|
||||
.Ar Host
|
||||
names may be names or internet numbers.
|
||||
.It Fl w
|
||||
Widen the duration field to show seconds, as well as the
|
||||
default days, hours and minutes.
|
||||
.El
|
||||
.Pp
|
||||
If
|
||||
|
|
|
@ -83,6 +83,8 @@ struct ttytab {
|
|||
static long currentout, /* current logout value */
|
||||
maxrec; /* records to display */
|
||||
static char *file = _PATH_WTMP; /* wtmp file */
|
||||
static int sflag = 0; /* show delta in seconds */
|
||||
static int width = 5; /* show seconds in delta */
|
||||
|
||||
void addarg __P((int, char *));
|
||||
void hostconv __P((char *));
|
||||
|
@ -91,6 +93,14 @@ char *ttyconv __P((char *));
|
|||
int want __P((struct utmp *));
|
||||
void wtmp __P((void));
|
||||
|
||||
void
|
||||
usage(void)
|
||||
{
|
||||
(void)fprintf(stderr,
|
||||
"usage: last [-#] [-f file] [-h hostname] [-t tty] [-s|w] [user ...]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
|
@ -104,7 +114,7 @@ main(argc, argv)
|
|||
(void) setlocale(LC_TIME, "");
|
||||
|
||||
maxrec = -1;
|
||||
while ((ch = getopt(argc, argv, "0123456789f:h:t:")) != -1)
|
||||
while ((ch = getopt(argc, argv, "0123456789f:h:st:w")) != -1)
|
||||
switch (ch) {
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
|
@ -129,16 +139,22 @@ main(argc, argv)
|
|||
hostconv(optarg);
|
||||
addarg(HOST_TYPE, optarg);
|
||||
break;
|
||||
case 's':
|
||||
sflag++; /* Show delta as seconds */
|
||||
break;
|
||||
case 't':
|
||||
addarg(TTY_TYPE, ttyconv(optarg));
|
||||
break;
|
||||
case 'w':
|
||||
width = 8;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
(void)fprintf(stderr,
|
||||
"usage: last [-#] [-f file] [-t tty] [-h hostname] [user ...]\n");
|
||||
exit(1);
|
||||
usage();
|
||||
}
|
||||
|
||||
if (sflag && width == 8) usage();
|
||||
|
||||
if (argc) {
|
||||
setlinebuf(stdout);
|
||||
for (argv += optind; *argv; ++argv) {
|
||||
|
@ -280,13 +296,18 @@ wtmp()
|
|||
printf("- %5.5s", ct + 11);
|
||||
}
|
||||
delta = tt->logout - bp->ut_time;
|
||||
tm = gmtime(&delta);
|
||||
(void) strftime(ct, sizeof(ct), "%c", tm);
|
||||
if (delta < 86400)
|
||||
printf(" (%5.5s)\n", ct + 11);
|
||||
else
|
||||
printf(" (%ld+%5.5s)\n",
|
||||
delta / 86400, ct + 11);
|
||||
if ( sflag ) {
|
||||
printf(" (%8lu)\n",
|
||||
delta);
|
||||
} else {
|
||||
tm = gmtime(&delta);
|
||||
(void) strftime(ct, sizeof(ct), "%c", tm);
|
||||
if (delta < 86400)
|
||||
printf(" (%*.*s)\n", width, width, ct + 11);
|
||||
else
|
||||
printf(" (%ld+%*.*s)\n",
|
||||
delta / 86400, width, width, ct + 11);
|
||||
}
|
||||
}
|
||||
LIST_REMOVE(tt, list);
|
||||
free(tt);
|
||||
|
|
Loading…
Reference in a new issue