logininit, estat, edf: Version 2.1 -- lots of info on login

Lenny Tropiano lenny at icus.islp.ny.us
Sun Jan 7 03:56:30 AEST 1990


See README2.1 for the most up-to-date information.  Since there were
a considerable amount of changes done, patches were not feasible.

-- cut here for shar -- -- cut here for shar -- -- cut here for shar --
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  README2.1 README2.0 README1.0 Makefile Makefile.386
#   logininit.c chtime.c fsinfo.sample fsinfo2.sample
# Wrapped by lenny at icus on Sat Jan  6 11:53:30 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f README2.1 -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"README2.1\"
else
echo shar: Extracting \"README2.1\" \(3185 characters\)
sed "s/^X//" >README2.1 <<'END_OF_README2.1'
X
XIn version 2.1, logininit has changed a bit.  The program is more "configurable"
Xby #defines located at the top of the logininit.c source.  All the functionality
Xof version 2.0 is there, plus some extra features.   Originally my /etc/profile
Xhad a call to run a previously posted program of mine called "lastlogin" which
Xrecorded the login time and tty in a Bezerkley type format file.  I've combined
Xthe functionality of logininit and lastlogin in this version.   Also the
Xmailbox reading function has been enhanced slightly.  If you are running a 
Xmail reader (eg. elm) that will update your mailbox when you Quit out and
Xadd lines like:
X
XStatus: O
X
XThe mail reading routine can now detect if you have "new" mail as well as
Xhow many new mail messages. If your mail reader doesn't support the "Status:"
Xfield, compile the program with "NEWMAIL" undefined, and it will work as
Xit did before.
X
XThe new improved format is:
X
XLast login: Sat Jan  6 10:45:44 on w1
X
XIt's Saturday, January 6, 1990 at 11:44am ... 
XNode: icus, up for 3 weeks, 0 hours, 51 minutes, and 15 seconds.
X/          HD1: System Partition    :  6.2MB,  12724 blocks,  6999 i-nodes, 15%
X/tmp       HD1: Sys Temp Partition  :  2.3MB,   4678 blocks,   259 i-nodes, 78%
X/usr/spool HD1: Spool Partition     :  4.4MB,   8976 blocks,  7063 i-nodes, 30%
X/usr/tmp   HD2: User Temp Partition :  2.2MB,   4450 blocks,   982 i-nodes, 56%
X/netnews   HD2: News Partition      :  9.2MB,  18852 blocks,  7021 i-nodes, 24%
X           Total Storage Available  : 24.3MB,  49680 blocks
X                            out of  :103.1MB, 211056 blocks, 24% free
X2.04MB of main memory currently available. (56%)
X
X        *****************************************************************
X        * Display the /etc/motd (Message-of-the-day) here, if it exists *
X        *****************************************************************
X
XYou have new mail! (30 mail messages, 3 unread in your mailbox)
X
XConfiguration ...
X
XLASTLOGIN
X	If this is defined the last login code will be done only if the
X	program name is called "logininit".  If not defined, it's not executed.
X
XSHOWTIME
X	Show the current date and time.
X
XUPTIME
X	Show machine name and uptime.
X
XFILESTATUS
X	Show the file system status, if not defined "edf" will be
X	empty and unnecessary.
X
XMEMORY
X	Show the available memory (MB) this is somewhat slow because
X	of nlist(). 
X
XSHOWMOTD
X	Display the /etc/motd if it exists
X
XMAILCHECK
X	Check the mail on the way ...
X
XNEWMAIL
X	Look for new mail "Status:" lines, if MAILCHECK is not defined
X	this option is useless.
X
XNOBEEP
X	Don't beep for anything (be quiet).
X
XREVERSE
X	Because of the way "df" works and the /etc/mnttab file is setup
X	on the 3B1 you probably want this defined.  Other machines can
X	be left undefined.
X
X
XThe program should be linked to "edf" and "estat".  estat will be just
Xlike logininit without any updating or printing of the last login and
Xtty.  edf is just the filesystem status.
X
X---
X| Lenny Tropiano            ICUS Software Systems      lenny at icus.islp.ny.us |
X| {ames,pacbell,decuac,hombre,sbcs,attctc}!icus!lenny     attmail!icus!lenny |
X+------- ICUS Software Systems -- PO Box 1;  Islip Terrace, NY  11752 -------+
END_OF_README2.1
if test 3185 -ne `wc -c <README2.1`; then
    echo shar: \"README2.1\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f README2.0 -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"README2.0\"
else
echo shar: Extracting \"README2.0\" \(2570 characters\)
sed "s/^X//" >README2.0 <<'END_OF_README2.0'
X
XIn version 2.0 of logininit, I modified it to handle multiple filesystems
Xthat are mounted on the hard disk.   This is done by looking up in /etc/mnttab
Xfor the currently mounted partitions and displaying the information.  Also
Xyou can describe the partition (up to 25 characters by putting it in a file
Xcalled /etc/fsinfo [which can be changed]).
X
X/etc/fsinfo:
Xfp002	/		HD1 : System Partition
Xfp003	/mnta		HD1 : Partition 2
Xfp003	/mntb		HD1 : Partition 2
Xfp011	/tmp		HD2 : Temporary Partition
Xfp011	/mnta		HD2 : Partition 1
Xfp011	/mntb		HD2 : Partition 1
Xfp012	/usr/spool	HD2 : Spool Partition
Xfp012	/mnta		HD2 : Partition 2
Xfp012	/mntb		HD2 : Partition 2
Xfp021	/mnt		FD  : Floppy Partition
Xfp021	/floppy		FD  : Floppy Partition
X
XI have two hard disks installed, so that is why fp01[12] is being accessed.
XThis is what ultimately pushed me to modify my older logininit.c.
X
XI also changed the output slightly, it looks nicer now. 
X
XNOTES:  The program looks at /etc/mnttab, and reads it backwards, much like
Xwhat "df(1)" does.  To get the partitions in the correct order, you basically
Xhave to set up the /etc/mnttab in reverse order.
X
X# devnm /usr/spool /tmp / | setmnt 
X# df 
X/         (/dev/fp002):    44596 blocks   11558 i-nodes
X/tmp      (/dev/fp011):     9788 blocks    1481 i-nodes
X/usr/spool(/dev/fp012):    25786 blocks   11672 i-nodes
X
X# devnm / /tmp /usr/spool | setmnt 
X# df 
X/usr/spool(/dev/fp012):    25786 blocks   11672 i-nodes
X/tmp      (/dev/fp011):     9788 blocks    1481 i-nodes
X/         (/dev/fp002):    44596 blocks   11558 i-nodes
X
XNew output format:
X------------------
XIt's Sunday, January 22, 1989 at 11:48pm ... 
XNode: icus, up for 3 hours, 41 minutes, and 4 seconds.
X/          HD1 : System Partition   : 21.8MB,  44618 blocks, 11562 i-nodes, 37%
X/tmp       HD2 : Temporary Partition:  4.8MB,   9794 blocks,  1482 i-nodes, 98%
X/usr/spool HD2 : News Partition     : 12.6MB,  25786 blocks, 11672 i-nodes, 36%
X/floppy    FD  : Floppy Partition   :  0.0MB,     64 blocks,     7 i-nodes,  9%
X           WARNING: Filesystem disk space is low.
X           WARNING: Filesystem i-nodes are low.
X           Total Storage Available  : 39.2MB,  80262 blocks
X                            out of  : 99.4MB, 203514 blocks, 39% free
X1.71MB of main memory currently available. (54%)
X
X        *****************************************************************
X        * Display the /etc/motd (Message-of-the-day) here, if it exists *
X        *****************************************************************
X
XYou have mail! (32 mail messages in your mailbox)
X
END_OF_README2.0
if test 2570 -ne `wc -c <README2.0`; then
    echo shar: \"README2.0\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f README1.0 -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"README1.0\"
else
echo shar: Extracting \"README1.0\" \(1989 characters\)
sed "s/^X//" >README1.0 <<'END_OF_README1.0'
X
XThis is a little ditty I whipped up one day... Basically it tells you all
Xkinds of neat stuff when you login.  It can be called from inside 
X/etc/profile and will print this kind of information...
X---
XIt's Tuesday, May 31, 1988 at 8:00pm ... 
XNode: icus, up for 22 hours, 38 minutes, and 27 seconds.
X21% available disk storage in the root filesystem. (26968 blocks, 8692 i-nodes)
X1.29MB of main memory currently available. (48%)
X
XNo mail.
X---
XIt's Tuesday, May 31, 1988 at 11:02pm ... 
XNode: icus, up for 1 day, 2 hours, 36 minutes, and 1 second.
X21% available disk storage in the root filesystem. (24968 blocks, 8777 i-nodes)
X1.45MB of main memory currently available. (54%)
X
X       **************************************************************
X       * This is my message of the day.  It can say whatever I like *
X       **************************************************************
X
XYou have mail! (13 mail messages in your mailbox)
X
X---
XIt will tell you when you have mail (and how many mail messages you have). It
Xprints the /etc/motd out so the call to "cat /etc/motd" can be removed from
X/etc/profile.
X
XAnother nice feature is that it monitors the space left on the hard disk
Xwhen you login.  It checks the percentage (%) left to MAXPERCENT (compile
Xtime option [defaults to 10%]) and the inodes left with MAXINODES [defaults
Xto 500].
X
XSnipped from /etc/profile
X
X...
X# Print login initialization information
X/usr/lbin/logininit
X
X#The following line (if uncommented) will set TERM and TERMCAP (see ttytype)
X#eval `tset -s -Q`
X#For now, just set TERM to s4
XNAME=`tty`
Xif [ \( "`expr $NAME : '/dev/w' `"      != "0" -o \
X	"`expr $NAME : '/dev/sys' `"    != "0" \) ]
Xthen
X...
X
Xlogininit is called before the question to ask what terminal you are
Xrunning on...  It can be put almost anywhere... Even in your /etc/localprofile
Xor wherever.   Remember to take out redundant processing from /etc/profile
Xlike the "if..fi" statement to check the mailbox status, and the 
X"cat /etc/motd"
X
END_OF_README1.0
if test 1989 -ne `wc -c <README1.0`; then
    echo shar: \"README1.0\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f Makefile -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"Makefile\"
else
echo shar: Extracting \"Makefile\" \(824 characters\)
sed "s/^X//" >Makefile <<'END_OF_Makefile'
X#
X# Makefile to compile logininit.c  (Login Information)
X# By Lenny Tropiano
X# (c)1988,1989,1990 ICUS Software Systems     EMAIL: lenny at icus.islp.ny.us
X# All rights reserved
X# For 3B1 running System V Release 3.5*
X#
XCFLAGS=-v -O -DMAXPERCENT=10 -DMAXINODES=100
XLDFLAGS=-s
XLIBS=/lib/crt0s.o /lib/shlib.ifile
XDEST=/usr/lbin/
X#
Xlogininit:  logininit.o chtime.o
X	@echo "Loading ..."
X	$(LD) $(LDFLAGS) -o logininit logininit.o chtime.o $(LIBS) 
X#
Xlogininit.o:
X	$(CC) $(CFLAGS) -c logininit.c
X#
X# You need to be super-user to do this.
X#
X$(DEST):
X	mkdir $(DEST)
X	chmod 755 $(DEST)
X#
Xinstall: logininit $(DEST)
X	rm -f $(DEST)/edf $(DEST)/estat
X	cp logininit $(DEST)
X	chown root $(DEST)/logininit
X	chgrp bin  $(DEST)/logininit
X	chmod 4755 $(DEST)/logininit
X	ln -f $(DEST)/logininit $(DEST)/edf
X	ln -f $(DEST)/logininit $(DEST)/estat
END_OF_Makefile
if test 824 -ne `wc -c <Makefile`; then
    echo shar: \"Makefile\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f Makefile.386 -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"Makefile.386\"
else
echo shar: Extracting \"Makefile.386\" \(732 characters\)
sed "s/^X//" >Makefile.386 <<'END_OF_Makefile.386'
X#
X# Makefile to compile logininit.c  (Login Information)
X# By Lenny Tropiano
X# (c)1988,1989,1990 ICUS Software Systems     EMAIL: lenny at icus.islp.ny.us
X# All rights reserved
X# For 6386WGS running System V Release 3.2
X#
XCFLAGS=-v -O
XLDFLAGS=-s
XLIBS=-lc_s
XDEST=/usr/lbin/
X#
Xlogininit:  logininit.o chtime.o
X	@echo "Loading ..."
X	$(CC) $(LDFLAGS) -o logininit logininit.o chtime.o $(LIBS) 
X#
Xlogininit.o:
X	$(CC) $(CFLAGS) -c logininit.c
X#
X# You need to be super-user to do this.
X#
X$(DEST):
X	mkdir $(DEST)
X	chmod 755 $(DEST)
X#
Xinstall: logininit $(DEST)
X	cp logininit $(DEST)
X	chown root $(DEST)/logininit
X	chgrp bin  $(DEST)/logininit
X	chmod 4755 $(DEST)/logininit
X	ln $(DEST)/logininit $(DEST)/edf
X	ln $(DEST)/logininit $(DEST)/estat
END_OF_Makefile.386
if test 732 -ne `wc -c <Makefile.386`; then
    echo shar: \"Makefile.386\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f logininit.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"logininit.c\"
else
echo shar: Extracting \"logininit.c\" \(15043 characters\)
sed "s/^X//" >logininit.c <<'END_OF_logininit.c'
X/************************************************************************\
X**                                                                      **
X** Program name: logininit.c (Login Initialization)                     **
X**                                                                      **
X**               edf, estat  (Same as logininit, they are links that    **
X**               should provide options like status info (estat) which  **
X**               will be like logininit without lastlogin (if enabled)  **
X**               and an option that prints only the filesystem info and **
X**               not the rest (edf).                                    **
X**                                                                      **
X** Programmer:   Lenny Tropiano        EMAIL: ...icus!lenny             **
X** Organization: ICUS Software Systems (c)1989/1990 All rights reserved **
X** Date:         April 3, 1988                                          **
X** Revision 2.0: January 19, 1989  - ability to handle more partitions  **
X**                                   as well as the description of each **
X** Revision 2.1: January  5, 1990  - cleaned up configuration, added    **
X**                                   the ability to detect new mail     **
X**                                   messages if your mail reader adds  **
X**                                   a "Status:" tag, added the last-   **
X**                                   login code in this program to      **
X**                                   obsolete the "lastlogin" program.  **
X**************************************************************************
X**                                                                      **
X** Program use:  Program is run as information apon login called from   **
X**               the /etc/profile. This program the filesystem          **
X**               information, available main memory and mail messages.  **
X**                                                                      **
X**   This programs must be setuid root (ie. 4755) and can be placed     **
X**   in any directory you choose.                                       **
X**                                                                      **
X**************************************************************************
X**                                                                      **
X**   Credits:  Thanks to Gil Kloepfer, Jr. (gil at limbic) for his insight **
X**   and suggestions about adding the capability of /etc/fsinfo, plus   **
X**   his many other suggestions in general.                             **
X**                                                                      **
X**************************************************************************
X** Permission granted to redistribute without profit in the public      **
X** domain only.  This header must remain in-tact as is.  This program   **
X** carries no warranties, express or implied, and all consequences      **
X** resulting from the use of this program are the sole responsibility   **
X** of the user.  Any modifications of this program must be mailed to    **
X** the author.                                                          **
X\************************************************************************/
X
X#include <stdio.h>
X#include <fcntl.h>
X#include <errno.h>
X#include <signal.h>
X#include <sys/types.h>
X#include <sys/param.h>
X#include <sys/filsys.h>
X#include <mnttab.h>
X#include <sys/utsname.h>
X#include <utmp.h>
X#include <time.h>
X#include <nlist.h>
X
X#ifndef ctob			
X#include <sys/sysmacros.h>
X#endif
X
X/************************************************************************/
X
X/*
X** Configuration options: change only stuff below here and before next
X**                        solid line of "*''s
X*/
X
X#define	LASTLOGIN		/* show the users last login time/tty  	*/
X#define	SHOWTIME		/* show the current time apon login	*/
X#define	UPTIME			/* show the uptime of the system	*/
X#define	FILESTATUS		/* examine the filesystem status	*/
X#define	MEMORY			/* display the available memory		*/
X#define	SHOWMOTD		/* print out the /etc/motd if available	*/
X#define	MAILCHECK		/* show the number of mail messages    	*/
X#define	NEWMAIL			/* calculate how many are new          	*/
X#undef	NOBEEP			/* if defined it will not beep at you	*/
X
X#define UNIX	"/unix"
X#define KMEM	"/dev/kmem"
X#define FSINFO	"/etc/fsinfo"
X#define MNTTAB	"/etc/mnttab"
X#define	LASTLOG	"/usr/adm/lastlogin.log"
X
X#ifndef MAXPERCENT
X# define MAXPERCENT	10		/* warn when less than 10% free	*/
X#endif
X
X#ifndef MAXINODES
X# define MAXINODES	500		/* warn when < 500 i-nodes free	*/
X#endif
X
X#define	REVERSE				/* display MNTTAB in reverse	*/
X
X/************************************************************************/
X
Xchar	*progname;			/* program name			*/
Xstruct  filsys fs;			/* Filesystem superblock struct */
Xstruct	tm	*today, *localtime();
Xstruct	nlist unixsym[] = {
X#define X_MAXMEM	0
X	{ "maxmem" },
X#define X_FREEMEM	1
X	{ "freemem" },
X	{ NULL }
X};
X
X#define MEGABYTE 1048576.0
X#define	DEVFMT	"/dev/r%s"	/* 3B1 device format		*/
X/* #define	DEVFMT	"%s"	/* 386 device format		*/
X
X/* declare all functions as nothing returned */
X
Xvoid	filestatus(),
X	describe(),
X	mailcheck(),
X	memory(),
X	uptime(),
X	showtime(),
X	show_motd(),
X	lastlogin(),
X	terminate();
X
X/************************************************************************/
X
Xmain(argc,argv)
Xint	argc;
Xchar	*argv[];
X{
X	char	*getenv(), *strrchr();
X	int	strcmp(), edfmode;
X
X	/* 
X	** Strip off any pathnames if they exist and only get the 
X	** program name.
X	*/
X    	if ((progname = (char *)(strrchr(*argv, '/'))) == (char *)NULL)
X		progname = *argv;
X	else    progname++;	/* skip of the "/"		*/
X
X#ifdef LASTLOGIN
X	if (strcmp(progname,"logininit") == 0)
X		lastlogin();	/* display last login time	*/
X#endif
X	if (strcmp(progname, "edf") == 0)
X		edfmode = 1;
X	else	edfmode = 0;
X
X	printf("\n");
X
X#ifdef SHOWTIME
X	if (!edfmode)
X		showtime();	/* what time is it?		*/
X#endif
X
X#ifdef UPTIME
X	if (!edfmode)
X		uptime();	/* get system uptime		*/
X#endif
X
X#ifdef FILESTATUS
X	filestatus();		/* get filesystem info		*/
X	if (edfmode)
X		terminate();
X#endif
X
X/*
X** will only get this far if the program isn't called "edf"
X*/
X
X#ifdef MEMORY
X	memory();		/* get current memory		*/
X#endif
X
X#ifdef SHOWMOTD
X	show_motd();		/* print the /etc/motd		*/
X#endif
X
X#ifdef MAILCHECK
X	mailcheck();		/* get mailbox status		*/
X#endif
X
X}
X
X#ifdef FILESTATUS
X/*
X** Show the filesystem status based on all the filesystems currently mounted
X** which is gotten from the /etc/mnttab file.
X*/
X
Xvoid filestatus()
X{
X	int	mntfd, fsfd, 
X		nmount, percleft;
X	float	megs, totmegs, maxmegs;
X	long	totblocks, maxblocks;
X	struct	mnttab	mtable;
X	char	rawdevice[12];
X
X	/* initialize */
X	nmount = totblocks = maxblocks = 0;
X	totmegs = maxmegs = 0.0;
X
X	if ((mntfd = open(MNTTAB, O_RDONLY)) == -1) {
X		fprintf(stderr,"%s: cannot open %s for read\n",
X			progname, MNTTAB);
X		return;
X	}
X
X#ifdef REVERSE
X	/* move to EOF */
X	if (lseek(mntfd, sizeof(struct mnttab) * -1, 2) == -1) {
X		fprintf(stderr,"%s: cannot lseek to end of file: %s\n",
X			progname, MNTTAB);
X		return;
X	}
X#endif
X
X	do  {
X
X	    read(mntfd, &mtable, sizeof(struct mnttab));
X
X	    sprintf(rawdevice, DEVFMT, mtable.mt_dev);
X	    if ((fsfd = open(rawdevice, O_RDONLY)) != -1) {
X	 	if (lseek(fsfd, 512, 0) == -1) {
X		    fprintf(stderr,"%s: cannot lseek to superblock\n", 
X			progname);
X		    return;
X	        }
X
X	        if (read(fsfd, &fs, sizeof(struct filsys)) == -1) {
X		    fprintf(stderr,"%s: cannot read the superblock\n", 
X			progname);
X		    return;
X	        }
X
X	    	close(fsfd);
X
X	    	percleft = (int)((((float)fs.s_tfree / (float)fs.s_fsize) 
X			+ 0.005) * 100.0);
X	    	megs = (fs.s_tfree * 1024) / MEGABYTE;
X	    	totmegs += megs;
X	    	totblocks += (fs.s_tfree * 2);
X	    	maxblocks += (fs.s_fsize * 2);
X
X	    	nmount++;
X
X	    	describe(mtable.mt_dev, mtable.mt_filsys);
X	    	printf(":%5.1fMB, %6d blocks, %5d i-nodes, %2d%%\n",
X			megs, fs.s_tfree * 2, fs.s_tinode, percleft);
X
X	    	if (percleft < MAXPERCENT) {
X			printf("           WARNING: Filesystem disk space is low.\n");
X#ifndef NOBEEP
X			putchar('\007');
X#endif
X		}
X	    	if (fs.s_tinode < MAXINODES) {
X			printf("           WARNING: Filesystem i-nodes are low.\n");
X#ifndef NOBEEP
X			putchar('\007');
X#endif
X		}
X	    } /* cannot open device */
X
X#ifdef REVERSE
X	} while (lseek(mntfd, sizeof(struct mnttab) * -2, 1) != -1);
X#else
X	} while (!errno);
X#endif
X
X	close(mntfd);
X
X	if (nmount > 1) {	/* more than on filesystem mounted */
X	    maxmegs = (maxblocks * 512) / MEGABYTE;
X	    percleft = (int)((((float)totblocks / maxblocks) + 0.005) 
X			* 100.0);
X	    printf("           Total Storage Available  :%5.1fMB, %6d blocks\n",
X		totmegs, totblocks);
X	    printf("                            out of  :%5.1fMB, %6d blocks, %2d%% free\n",
X		maxmegs, maxblocks, percleft);
X	}
X
X}
X
X/* 
X** Describe the filesystem by opening the /etc/fsinfo (#define FSINFO) file
X** and reading the appropriate description.  If there is no description just
X** print a blank area.
X*/
X
Xvoid describe(device, filesys)
Xchar *device, *filesys;
X{
X	FILE	*infofp;
X	int	devlen, fslen;
X	char	devbuf[12], fsbuf[12], infobuf[26];
X
X	devlen = strlen(device);
X	fslen  = strlen(filesys);
X
X	if ((infofp = fopen(FSINFO, "r")) != NULL) {
X	    while (fscanf(infofp, "%s %s %[\ -~]\n", 
X		devbuf, fsbuf, infobuf) > 0) {
X		if (strncmp(devbuf, device, devlen) == 0 &&
X		    strncmp(fsbuf, filesys, fslen) == 0) {
X			fclose(infofp);
X			printf("%-10.10s %-25.25s", filesys, infobuf);
X			return;
X		}
X	    }
X	    fclose(infofp);
X	}
X	printf("%-10.10s %-25.25s", filesys, " "); /* just blank info */
X}
X#endif
X
X#ifdef MAILCHECK
X
X/*
X** Read the users mail file (denoted by environment MAIL) and check for
X** the number of mail messages, if #define'd NEWMAIL then count the number
X** of "Status:" fields, and that will denote _old_ mail.
X*/
X
Xvoid mailcheck()
X{
X	FILE	*fp;
X	char	mailfile[30],		/* mailbox file name            */
X		buffer[BUFSIZ], 
X		*strrchr(), 
X		*getenv();
X	int	msgs = 0, forward = 0, line = 0, old = 0, newmail;
X
X	sprintf(mailfile,"%s",getenv("MAIL"));
X
X	if (access(mailfile,4) == 0) {
X		msgs = 0;
X		if ((fp = fopen(mailfile,"r")) != NULL) {
X			while (fgets(buffer, BUFSIZ, fp) != NULL) {
X				line++;
X				if (line == 1 &&
X				    strncmp(buffer,"Forward",7) == 0) {
X					forward = 1;
X					break;
X				}
X				if (strncmp(buffer,"From ",5) == 0)
X					msgs++;
X#ifdef NEWMAIL
X				else if (strncmp(buffer,"Status: ",8) == 0)
X					old++;
X#endif
X			}
X		}
X		fclose(fp);
X	} else  msgs = 0;
X
X	if (forward)
X		printf("Your mail is being forwarded to%s\n",
X			strrchr(buffer,' '));
X	else if (msgs != 0) {
X#ifdef NEWMAIL
X		buffer[0] = '\0';
X		if ((msgs - old) > 0) {
X			sprintf(buffer,", %d unread", msgs - old);
X			newmail = 1;
X		} else	newmail = 0;
X
X		printf("You have %smail! (%d mail message%s%s in your mailbox)\n",
X			(newmail) ? "new " : "", msgs,
X			(msgs == 1) ? "" : "s",
X			buffer);
X# ifndef NOBEEP
X			putchar('\007');
X# endif
X#else
X		printf("You have mail! (%d mail message%s in your mailbox)\n",
X			msgs, (msgs == 1) ? "" : "s");
X# ifndef NOBEEP
X			putchar('\007');
X# endif
X#endif
X	} else
X		printf("No mail.\n");
X}
X#endif
X
X#ifdef MEMORY
X
X/*
X** Open up /dev/kmem and read the free memory location, display the free
X** memory in megabytes
X*/
X
Xvoid memory()
X{
X	int	kmem;
X	int	maxmem, freemem;
X	float	megs, max, free, perc;
X
X	if (nlist(UNIX, unixsym) < 0) {
X		fprintf(stderr, "%s: no namelist.\n", UNIX);
X		return;
X	}
X
X	if ((kmem = open(KMEM, 0)) < 0) {
X		perror(KMEM);
X		return;
X	}
X
X	lseek(kmem, (long) unixsym[X_MAXMEM].n_value, 0);
X	read(kmem, (char *) &maxmem, sizeof(int));
X	lseek(kmem, (long) unixsym[X_FREEMEM].n_value, 0);
X	read(kmem, (char *) &freemem, sizeof(int));
X
X	close(kmem);
X
X	free = ctob(freemem);
X	max  = ctob(maxmem);
X	perc = free / max;
X	perc *= 100.0;
X
X	printf("%4.2fMB of main memory currently available. (%-2.0f%%)\n",
X		(ctob(freemem) / MEGABYTE), perc);
X		
X}
X#endif
X
X#ifdef UPTIME
X/*
X** Display the uptime found from the /etc/utmp file and the BOOT_TIME flag.
X*/
X
Xvoid uptime()
X{
X	int	now, boottime;
X	char	*up, *ch_time();
X	struct	utmp	*utent, *getutent();
X	struct	utsname	utsname;
X
X	time(&now);
X	today = localtime(&now);
X
X	setutent();
X	while ((utent = getutent()) != (struct utmp *)NULL) {
X		if (utent->ut_type == BOOT_TIME) {
X			boottime = utent->ut_time;
X			break;
X		}
X	}
X	endutent();
X
X	up = ch_time(now - boottime);
X	uname(&utsname);
X	printf("Node: %s, up for %s\n", utsname.nodename, up);
X
X}
X#endif
X
X#ifdef SHOWTIME
X/* 
X** Display the current time in a human-readable format
X*/
X
Xvoid showtime()
X{
X	int	now, ampm;
X	extern	char	*day[], *mon[];
X
X	time(&now);
X	today = localtime(&now);
X
X	if (today->tm_hour == 0) {
X		ampm = 0;
X		today->tm_hour += 12;
X	} else if (today->tm_hour > 12) {
X		ampm = 1;
X		today->tm_hour -= 12;
X	} else  if (today->tm_hour == 12)
X		ampm = 1;
X	else	ampm = 0;
X
X	printf("It's %s, %s %d, %d at %2d:%.2d%s ... \n",
X		day[today->tm_wday], mon[today->tm_mon], today->tm_mday,
X		today->tm_year + 1900, today->tm_hour, today->tm_min,
X		(ampm == 0) ? "am" : "pm");
X
X}
X#endif
X
X#ifdef SHOWMOTD
X/*
X** Display the /etc/motd file if it's there...
X*/
X
Xvoid show_motd()
X{
X	FILE	*fp;
X	char	buffer[BUFSIZ];
X
X	printf("\n");
X	if ((fp = fopen("/etc/motd","r")) != NULL) {
X		while (fgets(buffer, BUFSIZ, fp) != NULL) 
X			printf("%s", buffer);
X	
X		fclose(fp);
X	}
X	printf("\n");
X}
X#endif
X
X#ifdef LASTLOGIN
X
X/*
X** Open up the last login log file, and display the current users last
X** login time (this is much like Berkeley format which should work for
X** programs like "finger")
X*/
X
Xvoid lastlogin()
X{
X	struct utmp *utent, *getutent();
X	int    fd;
X	long   hrs, min, sec;
X	struct lastlog {
X		char	ll_line[8];
X		time_t	ll_time;
X	} ll;
X
X	if (access(LASTLOG, 0) == -1) {
X		if ((fd = creat(LASTLOG,0644)) == -1) {
X			fprintf(stderr,"%s: cannot create file %s: ", 
X				progname, LASTLOG);
X			perror("creat()");
X			return;
X	   	}
X	} else {
X		if ((fd = open(LASTLOG,O_RDWR)) == -1) {
X			fprintf(stderr,"%s: cannot open file %s: ", 
X				progname, LASTLOG);
X			perror("open()");
X			return;
X		}
X	}
X
X	if (lseek(fd, (long)(getuid()*sizeof(struct lastlog)), 0) == -1) {
X		fprintf(stderr,"%s: cannot position file %s: ", 
X			progname, LASTLOG);
X		perror("lseek()");
X		return;
X	}
X
X	if (read(fd, (char *) &ll, sizeof ll) == sizeof ll &&
X	    ll.ll_time != 0L) {
X		printf("Last login: %-19.19s on %.*s\n",
X			(char *)ctime(&ll.ll_time),
X			sizeof(ll.ll_line),
X			ll.ll_line);
X	} else  printf("Last login: no previous login information on record\n");
X
X	sprintf(ll.ll_line, "%.8s", strrchr(ttyname(0), '/') + 1);
X	setutent();
X	while ((utent = (struct utmp *)getutent()) != NULL) 
X		if (strcmp(utent->ut_line, ll.ll_line) == 0)
X			break;
X
X	if (utent == (struct utmp *)NULL) {
X		fprintf(stderr,"%s: cannot locate utmp entry for tty\n",
X			progname);
X		return;
X	}
X	ll.ll_time = utent->ut_time;
X	endutent();
X
X	lseek(fd, (long)(getuid()*sizeof(struct lastlog)), 0);
X	write(fd, (char *) &ll, sizeof ll);
X	close(fd);
X}
X#endif
X
X/*
X** exit out smoothly ...
X*/
X
Xvoid terminate()
X{
X	printf("\n");
X	exit(0);
X}
END_OF_logininit.c
if test 15043 -ne `wc -c <logininit.c`; then
    echo shar: \"logininit.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f chtime.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"chtime.c\"
else
echo shar: Extracting \"chtime.c\" \(1648 characters\)
sed "s/^X//" >chtime.c <<'END_OF_chtime.c'
X/*
X * ch_time - format elapsed time into a character string.
X *
X * Mikel Manitius - 85-01-08 - (mikel at codas.att.com.uucp)
X * Lenny Tropiano - 88-04-14 - (lenny at icus.UUCP) - modified slightly
X *
X */
X
X#define			NULL		(0)
X#define			SECOND		1L
X#define			MINUTE		60L
X#define			HOUR		(60L * 60L)
X#define			DAY		(24L * 60L * 60L)
X#define			WEEK		(7L  * 24L * 60L * 60L)
X#define			BUFSIZE		1024
X
Xchar	*malloc();
X
Xchar	*day[] =
X{
X	"Sunday", "Monday", "Tuesday",
X	"Wednesday", "Thursday", "Friday",
X	"Saturday", 0
X};
X
Xchar	*mon[] =
X{
X	"January", "February", "March", "April", "May",
X	"June", "July", "August", "September", "October",
X	"November", "December", 0
X};
X
X
Xchar *ch_time(sec)
Xint	sec;
X{
X	unsigned long	hrs = 0L;
X	unsigned long	days = 0L;
X	unsigned long	mins = 0L;
X	unsigned long	weeks = 0L;
X	char	*buff;
X
X	buff = malloc(BUFSIZE);
X	if(buff == NULL)
X		return(NULL);
X	weeks = sec / WEEK;
X	sec -= WEEK * weeks;
X	days = sec / DAY;
X	sec -= DAY * days;
X	hrs = sec / HOUR;
X	sec -= HOUR * hrs;
X	mins = sec / MINUTE;
X	sec -= MINUTE * mins;
X
X	if(weeks)
X		sprintf(buff, "%d week%s, ", weeks, (weeks == 1) ? "" : "s");
X	if(days)
X		sprintf(buff, "%s%d day%s, ", (weeks) ? buff : "",
X			days, (days == 1L) ? "" : "s");
X	if(hrs || days || weeks)
X		sprintf(buff, "%s%d hour%s, ", (days || weeks) ? buff : "",
X			hrs, (hrs == 1L) ? "" : "s");
X	if(mins || hrs || days || weeks)
X		sprintf(buff, "%s%d minute%s, ",
X			(hrs || days || weeks) ? buff : "",
X			mins, (mins == 1L) ? "" : "s");
X	sprintf(buff, "%s%s%d second%s.",
X			(mins || hrs || days || weeks) ? buff : "",
X			(mins || hrs || days || weeks) ? "and " : "",
X			sec, (sec == 1L) ? "" : "s");
X	return(buff);
X}
END_OF_chtime.c
if test 1648 -ne `wc -c <chtime.c`; then
    echo shar: \"chtime.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f fsinfo.sample -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"fsinfo.sample\"
else
echo shar: Extracting \"fsinfo.sample\" \(368 characters\)
sed "s/^X//" >fsinfo.sample <<'END_OF_fsinfo.sample'
Xfp002	/		HD1 : System Partition
Xfp003	/mnta		HD1 : Partition 2
Xfp003	/mntb		HD1 : Partition 2
Xfp011	/tmp		HD2 : Temporary Partition
Xfp011	/mnta		HD2 : Partition 1
Xfp011	/mntb		HD2 : Partition 1
Xfp012	/usr/spool	HD2 : Spool Partition
Xfp012	/mnta		HD2 : Partition 2
Xfp012	/mntb		HD2 : Partition 2
Xfp021	/mnt		FD  : Floppy Partition
Xfp021	/floppy		FD  : Floppy Partition
END_OF_fsinfo.sample
if test 368 -ne `wc -c <fsinfo.sample`; then
    echo shar: \"fsinfo.sample\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f fsinfo2.sample -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"fsinfo2.sample\"
else
echo shar: Extracting \"fsinfo2.sample\" \(530 characters\)
sed "s/^X//" >fsinfo2.sample <<'END_OF_fsinfo2.sample'
Xfp002	/		HD1: System Partition
Xfp003	/mnta		HD1: Partition 2
Xfp003	/mntb		HD1: Partition 2
Xfp003	/tmp		HD1: Sys Temp Partition
Xfp004	/usr/spool	HD1: Spool Partition
Xfp011	/mnta		HD2: Partition 1
Xfp011	/mntb		HD2: Partition 1
Xfp011	/usr/tmp	HD2: User Temp Partition
Xfp012	/netnews	HD2: News Partition
Xfp012	/mnta		HD2: Partition 2
Xfp012	/mntb		HD2: Partition 2
Xfp013	/archives	HD2: Archive Partition
Xfp013	/mnta		HD2: Partition 3
Xfp013	/mntb		HD2: Partition 3
Xfp021	/mnt		FD : Floppy Partition
Xfp021	/floppy		FD : Floppy Partition
END_OF_fsinfo2.sample
if test 530 -ne `wc -c <fsinfo2.sample`; then
    echo shar: \"fsinfo2.sample\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0
-- 
| Lenny Tropiano            ICUS Software Systems      lenny at icus.islp.ny.us |
| {ames,pacbell,decuac,hombre,sbcs,attctc}!icus!lenny     attmail!icus!lenny |
+------- ICUS Software Systems -- PO Box 1;  Islip Terrace, NY  11752 -------+



More information about the Comp.sys.att mailing list