Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 12 Jan 2002 01:26:31 +0200
From:      Giorgos Keramidas <keramida@ceid.upatras.gr>
To:        audit@FreeBSD.org
Subject:   last with -y option
Message-ID:  <20020111232631.GA66629@hades.hell.gr>

next in thread | raw e-mail | index | archive | help

--8GpibOaaTibBMecb
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

The patch that was sent in PR bin/12982 does not apply to the
usr.bin/last (probably because our last was modified for WARNS=2 after
the patch was submitted), but I liked the idea that it describes.

The attached patch adds a -y option to last that will print the year
too when listing wtmp records. It also removes a few EOL whitespaces
that I found while reading the last.c source.

If this does not break any standards, and you don't think that it
breaks last(1) in some way, I'll have to find myself an src/ committer
to take care of this PR :-)

Cheers,

-- 
Giorgos Keramidas . . . . . . . . . keramida@{ceid.upatras.gr,freebsd.org}
FreeBSD Documentation Project . . . http://www.freebsd.org/docproj/
FreeBSD: The power to serve . . . . http://www.freebsd.org/

--8GpibOaaTibBMecb
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="28.last-y.diff"
Content-Transfer-Encoding: quoted-printable

Index: last.1
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/usr.bin/last/last.1,v
retrieving revision 1.11
diff -u -2 -r1.11 last.1
--- last.1	10 Jul 2001 14:16:03 -0000	1.11
+++ last.1	9 Dec 2001 01:52:36 -0000
@@ -56,4 +56,5 @@
 .Op Fl t Ar tty
 .Op Fl w
+.Op Fl y
 .Op Ar user ...
 .Sh DESCRIPTION
@@ -162,4 +163,6 @@
 Widen the duration field to show seconds, as well as the
 default days, hours and minutes.
+.It Fl w
+Report years too in the login session duration.
 .El
 .Pp
Index: last.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/usr.bin/last/last.c,v
retrieving revision 1.21
diff -u -2 -r1.21 last.c
--- last.c	29 Oct 2001 00:34:20 -0000	1.21
+++ last.c	11 Jan 2002 23:15:48 -0000
@@ -90,4 +90,5 @@
 static int	sflag =3D 0;			/* show delta in seconds */
 static int	width =3D 5;			/* show seconds in delta */
+static int	yflag =3D 0;			/* show years in delta */
 static int      d_first;
 static time_t	snaptime;			/* if !=3D 0, we will only
@@ -110,5 +111,5 @@
 	(void)fprintf(stderr,
 "usage: last [-#] [-d [[CC]YY][MMDD]hhmm[.SS]] [-f file] [-h hostname]\n"
-"\t[-t tty] [-s|w] [user ...]\n");
+"\t[-t tty] [-s|w] [-y] [user ...]\n");
 	exit(1);
 }
@@ -127,5 +128,5 @@
 	maxrec =3D -1;
 	snaptime =3D 0;
-	while ((ch =3D getopt(argc, argv, "0123456789d:f:h:st:w")) !=3D -1)
+	while ((ch =3D getopt(argc, argv, "0123456789d:f:h:st:wy")) !=3D -1)
 		switch (ch) {
 		case '0': case '1': case '2': case '3': case '4':
@@ -164,4 +165,7 @@
 			width =3D 8;
 			break;
+		case 'y':
+			yflag =3D 1;
+			break;
 		case '?':
 		default:
@@ -246,13 +250,22 @@
 				/*
 				 * don't print shutdown/reboot entries
-				 * unless flagged for=20
-				 */=20
+				 * unless flagged for
+				 */
 				if (!snaptime && want(bp)) {
 					t =3D int_to_time(bp->ut_time);
 					tm =3D localtime(&t);
-					(void) strftime(ct, sizeof(ct),
-						     d_first ? "%a %e %b %R" :
-							       "%a %b %e %R",
-						     tm);
+					if (yflag) {
+						(void) strftime(ct, sizeof(ct),
+							     d_first
+							     ? "%a %e %b %Y %R"
+							     : "%a %b %e %Y %R",
+							     tm);
+					} else {
+						(void) strftime(ct, sizeof(ct),
+							     d_first
+							     ? "%a %e %b %Y %R"
+							     : "%a %b %e %Y %R",
+							     tm);
+					}
 					printf("%-*.*s %-*.*s %-*.*s %s\n",
 					    UT_NAMESIZE, UT_NAMESIZE,
@@ -275,8 +288,17 @@
 					t =3D int_to_time(bp->ut_time);
 					tm =3D localtime(&t);
-					(void) strftime(ct, sizeof(ct),
-						     d_first ? "%a %e %b %R" :
-							       "%a %b %e %R",
-						     tm);
+					if (yflag) {
+						(void) strftime(ct, sizeof(ct),
+							     d_first
+							     ? "%a %e %b %Y %R"
+							     : "%a %b %e %Y %R",
+							     tm);
+					} else {
+						(void) strftime(ct, sizeof(ct),
+							     d_first
+							     ? "%a %e %b %R"
+							     : "%a %b %e %R",
+							     tm);
+					}
 					printf("%-*.*s %-*.*s %-*.*s %s\n",
 					    UT_NAMESIZE, UT_NAMESIZE, bp->ut_name,
@@ -293,5 +315,5 @@
 			    if (!strncmp(tt->tty, bp->ut_line, UT_LINESIZE))
 				    break;
-		=09
+
 			if (tt =3D=3D NULL) {
 				/* add new one */
@@ -303,5 +325,5 @@
 				LIST_INSERT_HEAD(&ttylist, tt, list);
 			}
-		=09
+
 			/*
 			 * print record if not in snapshot mode and wanted
@@ -323,8 +345,15 @@
 				t =3D int_to_time(bp->ut_time);
 				tm =3D localtime(&t);
-				(void) strftime(ct, sizeof(ct),
-				    d_first ? "%a %e %b %R" :
-				    "%a %b %e %R",
-				    tm);
+				if (yflag) {
+					(void) strftime(ct, sizeof(ct),
+					    d_first ? "%a %e %b %Y %R" :
+					    "%a %b %e %Y %R",
+					    tm);
+				} else {
+					(void) strftime(ct, sizeof(ct),
+					    d_first ? "%a %e %b %R" :
+					    "%a %b %e %R",
+					    tm);
+				}
 				printf("%-*.*s %-*.*s %-*.*s %s ",
 				    UT_NAMESIZE, UT_NAMESIZE, bp->ut_name,
@@ -346,5 +375,5 @@
 					delta =3D tt->logout - bp->ut_time;
 					if ( sflag ) {
-						printf("  (%8ld)\n",=20
+						printf("  (%8ld)\n",
 						    (long)delta);
 					} else {

--8GpibOaaTibBMecb--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020111232631.GA66629>