*BSD News Article 31928


Return to BSD News archive

Xref: sserve comp.os.386bsd.development:2284 comp.unix.bsd:14209
Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!bunyip.cc.uq.oz.au!munnari.oz.au!goanna.cs.rmit.oz.au!not-for-mail
From: lm@goanna.cs.rmit.oz.au (Luke Mewburn)
Newsgroups: comp.os.386bsd.development,comp.unix.bsd
Subject: Improvements to finger(1)
Date: 11 Jun 1994 12:11:48 +1000
Organization: Technical Services Group, Dept. of Computer Science, RMIT
Lines: 350
Message-ID: <2tb6h4$pnu@goanna.cs.rmit.oz.au>
Reply-To: lm@rmit.edu.au
NNTP-Posting-Host: goanna.cs.rmit.oz.au
NNTP-Posting-User: lm

A long time ago I ported net/2 (actually netbsd 0.8) finger to Solaris 2.
In the process I added mail status reporting & hostname display so the
output would be similar to solaris'. At the time, I posted the diffs
for the former (mail status reporting.) for Net/2 finger to this group
which has been integrated into netbsd's finger.  A few months ago I
kludged in the hostname reporting back into my copy of the netbsd finger too.
Here is that patch (yet to be incorporated into NetBSD).

What it does is changes the default short display from displaying
office information to displaying remote host info (which is much more
useful; because that way you know if the person is least idle from
home or work, etc.)  Another change is that if the login time is less
than a week ago, it prints the name of the day instead of it's date
(e.g, `Fri' instead of `Jun 3'.) which, again, I feel is better since
I know what day it is but the date often eludes me :)

Both of these ideas were from SunOS/Solaris. I know, ``NetBSD Is
Not SunOS'' but I feel that these cosmetic changes make finger more
presentable. You can get the old output back with -o (-h & -o toggle
host & office info.)

Here's a sample output:

---
lm@karybdis 60 ...local/src/finger> finger
Login    Name                 Tty  Idle   Login Time   Where
lm       Luke Mewburn          p0     -    Sun  23:13  goanna.cs.rmit.O
lm       Luke Mewburn          p2     -    Mon  14:33
simonb   Simon Burge           p1  1:05    Mon  13:38  149.135.252.11
lm@karybdis 61 ...local/src/finger> finger @karybdis
[karybdis.cs.rmit.OZ.AU]
Login    Name                 Tty  Idle   Login Time   Where
lm       Luke Mewburn          p0     -    Sun  23:13  goanna.cs.rmit.O
lm       Luke Mewburn          p2     -    Mon  14:33
simonb   Simon Burge           p1  1:05    Mon  13:38  149.135.252.11
lm@karybdis 62 ...local/src/finger> finger -o
Login    Name                 Tty  Idle   Login Time  Office     Office Phone
lm       Luke Mewburn          p0     -    Sun  23:13 10.10.16   x3210
lm       Luke Mewburn          p2     -    Mon  14:33 10.10.16   x3210
simonb   Simon Burge           p1  1:05    Mon  13:38 xxxxxxx    xxx-xxxx
---
(Notice remote fingers have changed because finger has. Also, the
login time for myself was `Sun' (Sunday) which I can relate to
much easier than `Jun 5'.)

I'm posting this here so that other BSD freaks (and people who like to
use the bsd finger on their systems) can get this functionality too.

[This diff should be applied against the Net/2 finger which has
already had my mailstatus reporting diffs applied. If you don't have
this, I can probably send you a tar.gz.uu of the modified sources.]

Patches follow:
--- cut here --- file: fingerdiff
diff -c -b /usr/src/usr.bin/finger/finger.1 finger/finger.1
*** /usr/src/usr.bin/finger/finger.1	Tue Feb 15 21:19:28 1994
--- finger/finger.1	Mon Jun  6 14:59:53 1994
***************
*** 32,38 ****
  .\"	from: @(#)finger.1	6.14 (Berkeley) 7/27/91
  .\"	$Id: finger.1,v 1.4 1994/02/14 19:07:33 cgd Exp $
  .\"
! .Dd July 27, 1991
  .Dt FINGER 1
  .Os BSD 4
  .Sh NAME
--- 32,38 ----
  .\"	from: @(#)finger.1	6.14 (Berkeley) 7/27/91
  .\"	$Id: finger.1,v 1.4 1994/02/14 19:07:33 cgd Exp $
  .\"
! .Dd June 6, 1994
  .Dt FINGER 1
  .Os BSD 4
  .Sh NAME
***************
*** 40,46 ****
  .Nd user information lookup program
  .Sh SYNOPSIS
  .Nm finger
! .Op Fl lmsp
  .Op Ar user ...
  .Op Ar user@host ...
  .Sh DESCRIPTION
--- 40,46 ----
  .Nd user information lookup program
  .Sh SYNOPSIS
  .Nm finger
! .Op Fl lmpsho
  .Op Ar user ...
  .Op Ar user@host ...
  .Sh DESCRIPTION
***************
*** 54,67 ****
  .Nm Finger
  displays the user's login name, real name, terminal name and write
  status (as a ``*'' before the terminal name if write permission is
! denied), idle time, login time, office location and office phone
! number.
  .Pp
  Idle time is in minutes if it is a single integer, hours and minutes
  if a ``:'' is present, or days if a ``d'' is present.
! Login time is displayed as month, day, hours and minutes, unless
! more than six months ago, in which case the year is displayed rather
! than the hours and minutes.
  .Pp
  Unknown devices as well as nonexistent idle and login times are
  displayed as single asterisks.
--- 54,72 ----
  .Nm Finger
  displays the user's login name, real name, terminal name and write
  status (as a ``*'' before the terminal name if write permission is
! denied), idle time, login time, and either office location and office
! phone number, or the remote host. If
! .Fl h
! is given, the remote host is printed (the default.) If
! .Fl o
! is given, the office location and office phone number is printed
! instead.
  .Pp
  Idle time is in minutes if it is a single integer, hours and minutes
  if a ``:'' is present, or days if a ``d'' is present.
! Login time is displayed as dayname if less than 6 days, else month,
! day; hours and minutes, unless more than six months ago, in which
! case the year is displayed rather than the hours and minutes.
  .Pp
  Unknown devices as well as nonexistent idle and login times are
  displayed as single asterisks.
***************
*** 99,104 ****
--- 104,119 ----
  at their mailbox since new mail arriving, or ``New mail received ...'',
  ``  Unread since ...'' if they have new mail.
  .Pp
+ .It Fl h
+ When used in conjunction with the
+ .Fl s 
+ option, the name of the remote host is displayed instead of the office
+ location and office phone.
+ .It Fl o
+ When used in conjunction with the
+ .Fl s 
+ option, the office location and office phone information is displayed
+ instead of the name of the remote host.
  .It Fl p
  Prevents
  the
diff -c -b /usr/src/usr.bin/finger/finger.c finger/finger.c
*** /usr/src/usr.bin/finger/finger.c	Fri Dec 17 18:11:10 1993
--- finger/finger.c	Mon Jun  6 15:02:32 1994
***************
*** 35,41 ****
   */

  /*
!  * Mail status reporting added 931007 by Luke Mewburn, <zak@rmit.edu.au>.
   */

  #ifndef lint
--- 35,42 ----
   */

  /*
!  * Mail status reporting added 931007 by Luke Mewburn, <lm@rmit.edu.au>.
!  * Host/office toggling added 940606 by Luke Mewburn, <lm@rmit.edu.au>.
   */

  #ifndef lint
***************
*** 57,65 ****
   *
   * There are currently two output formats; the short format is one line
   * per user and displays login name, tty, login time, real name, idle time,
!  * and office location/phone number.  The long format gives the same
!  * information (in a more legible format) as well as home directory, shell,
!  * mail info, and .plan/.project files.
   */

  #include <sys/param.h>
--- 58,67 ----
   *
   * There are currently two output formats; the short format is one line
   * per user and displays login name, tty, login time, real name, idle time,
!  * and either office location/phone number or remote host info, depending
!  * upon if -o, or -h (the default) is used respectively.
!  * The long format gives the same information (in a more legible format) as
!  * well as home directory, shell, mail info, and .plan/.project files.
   */

  #include <sys/param.h>
***************
*** 69,74 ****
--- 71,77 ----

  time_t now;
  int lflag, sflag, mflag, pplan;
+ int hflag;
  char tbuf[1024];

  main(argc, argv)
***************
*** 79,85 ****
  	int ch;
  	time_t time();

! 	while ((ch = getopt(argc, argv, "lmps")) != EOF)
  		switch(ch) {
  		case 'l':
  			lflag = 1;		/* long format */
--- 82,89 ----
  	int ch;
  	time_t time();

! 	hflag = 1;		/* print remote host by default */
! 	while ((ch = getopt(argc, argv, "lmpsho")) != EOF)
  		switch(ch) {
  		case 'l':
  			lflag = 1;		/* long format */
***************
*** 93,102 ****
  		case 's':
  			sflag = 1;		/* short format */
  			break;
  		case '?':
  		default:
  			(void)fprintf(stderr,
! 			    "usage: finger [-lmps] [login ...]\n");
  			exit(1);
  		}
  	argc -= optind;
--- 97,112 ----
  		case 's':
  			sflag = 1;		/* short format */
  			break;
+ 		case 'h':
+ 			hflag = 1;		/* print host, not office */
+ 			break;
+ 		case 'o':
+ 			hflag = 0;		/* print office, not host */
+ 			break;
  		case '?':
  		default:
  			(void)fprintf(stderr,
! 			    "usage: finger [-lmpsho] [login ...]\n");
  			exit(1);
  		}
  	argc -= optind;
Common subdirectories: /usr/src/usr.bin/finger/obj and finger/obj
diff -c -b /usr/src/usr.bin/finger/sprint.c finger/sprint.c
*** /usr/src/usr.bin/finger/sprint.c	Fri Dec 17 18:11:12 1993
--- finger/sprint.c	Mon Jun  6 14:47:36 1994
***************
*** 50,55 ****
--- 50,56 ----
  sflag_print()
  {
  	extern time_t now;
+ 	extern int    hflag;
  	register PERSON *pn;
  	register WHERE *w;
  	register int cnt;
***************
*** 67,80 ****
  	 *	if terminal writeable (add an '*' to the terminal name
  	 *		if not)
  	 *	if logged in show idle time and day logged in, else
! 	 *		show last login date and time.  If > 6 moths,
! 	 *		show year instead of time.
  	 *	office location
  	 *	office phone
  	 */
  #define	MAXREALNAME	20
! 	(void)printf("%-*s %-*s %s\n", UT_NAMESIZE, "Login", MAXREALNAME,
! 	    "Name", "Tty  Idle  Login Time   Office     Office Phone");
  	for (cnt = 0; cnt < entries; ++cnt) {
  		pn = list[cnt];
  		for (w = pn->whead; w != NULL; w = w->next) {
--- 68,88 ----
  	 *	if terminal writeable (add an '*' to the terminal name
  	 *		if not)
  	 *	if logged in show idle time and day logged in, else
! 	 *		show last login date and time.  If > 6 months,
! 	 *		show year instead of time. If < 6 days,
! 	 *		show day name instead of month & day.
! 	 *	if (-h) given (default):
! 	 *		remote host
! 	 *	else if (-o) given	(mutually exclusive to -h)
  	 *		office location
  	 *		office phone
  	 */
  #define	MAXREALNAME	20
! #define MAXHOSTNAME	20
! 	    /* "Name", "Tty  Idle  Login Time   Office     Office Phone"); */
! 	(void)printf("%-*s %-*s %s  %s\n", UT_NAMESIZE, "Login", MAXREALNAME,
! 	    "Name", "Tty  Idle   Login Time", (hflag) ? " Where"
! 						     : "Office     Office Phone");
  	for (cnt = 0; cnt < entries; ++cnt) {
  		pn = list[cnt];
  		for (w = pn->whead; w != NULL; w = w->next) {
***************
*** 99,116 ****
  			} else
  				(void)printf("    *  ");
  			p = ctime(&w->loginat);
  			(void)printf("%.6s", p + 4);
  			if (now - w->loginat >= SECSPERDAY * DAYSPERNYEAR / 2)
  				(void)printf("  %.4s", p + 20);
  			else
  				(void)printf(" %.5s", p + 11);
! office:			if (pn->office)
  				(void)printf(" %-10.10s", pn->office);
  			else if (pn->officephone)
  				(void)printf(" %-10.10s", " ");
  			if (pn->officephone)
  				(void)printf(" %-.15s",
  				    prphone(pn->officephone));
  			putchar('\n');
  		}
  	}
--- 107,132 ----
  			} else
  				(void)printf("    *  ");
  			p = ctime(&w->loginat);
+ 			if (now - w->loginat < SECSPERDAY * (DAYSPERWEEK - 1))
+ 				(void)printf("  %.3s ", p);
+ 			else
  				(void)printf("%.6s", p + 4);
  			if (now - w->loginat >= SECSPERDAY * DAYSPERNYEAR / 2)
  				(void)printf("  %.4s", p + 20);
  			else
  				(void)printf(" %.5s", p + 11);
! office:			
! 			if (hflag)
! 				(void)printf("  %.*s", MAXHOSTNAME, w->host);
! 			else {
! 				if (pn->office)
  					(void)printf(" %-10.10s", pn->office);
  				else if (pn->officephone)
  					(void)printf(" %-10.10s", " ");
  				if (pn->officephone)
  					(void)printf(" %-.15s",
  					    prphone(pn->officephone));
+ 			}
  			putchar('\n');
  		}
  	}
--- cut here ---

---
Luke Mewburn             UNIX Systems Programmer, Technical Services Group
<lm@rmit.edu.au>               Department of Computer Science, RMIT.