xref: /titanic_51/usr/src/cmd/acct/lastlogin.sh (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate#!/sbin/sh
2*7c478bd9Sstevel@tonic-gate#
3*7c478bd9Sstevel@tonic-gate# CDDL HEADER START
4*7c478bd9Sstevel@tonic-gate#
5*7c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*7c478bd9Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
7*7c478bd9Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
8*7c478bd9Sstevel@tonic-gate# with the License.
9*7c478bd9Sstevel@tonic-gate#
10*7c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11*7c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
12*7c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
13*7c478bd9Sstevel@tonic-gate# and limitations under the License.
14*7c478bd9Sstevel@tonic-gate#
15*7c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
16*7c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17*7c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
18*7c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
19*7c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
20*7c478bd9Sstevel@tonic-gate#
21*7c478bd9Sstevel@tonic-gate# CDDL HEADER END
22*7c478bd9Sstevel@tonic-gate#
23*7c478bd9Sstevel@tonic-gate#	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
24*7c478bd9Sstevel@tonic-gate#	  All Rights Reserved
25*7c478bd9Sstevel@tonic-gate
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate#ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.6	*/
28*7c478bd9Sstevel@tonic-gate#	"lastlogin - keep record of date each person last logged in"
29*7c478bd9Sstevel@tonic-gate#	"bug - the date shown is usually 1 more than it should be "
30*7c478bd9Sstevel@tonic-gate#	"       because lastlogin is run at 4am and checks the last"
31*7c478bd9Sstevel@tonic-gate#	"       24 hrs worth of process accounting info (in pacct)"
32*7c478bd9Sstevel@tonic-gatePATH=/usr/lib/acct:/usr/bin:/usr/sbin
33*7c478bd9Sstevel@tonic-gatecd /var/adm/acct
34*7c478bd9Sstevel@tonic-gateif test ! -r sum/loginlog; then
35*7c478bd9Sstevel@tonic-gate	nulladm sum/loginlog
36*7c478bd9Sstevel@tonic-gatefi
37*7c478bd9Sstevel@tonic-gate#	"cleanup loginlog - delete entries of those no longer in"
38*7c478bd9Sstevel@tonic-gate#	"/etc/passwd and add an entry for those recently added"
39*7c478bd9Sstevel@tonic-gate#	"line 1 - get file of current logins in same form as loginlog"
40*7c478bd9Sstevel@tonic-gate#	"line 2 - merge the 2 files; use uniq to delete common"
41*7c478bd9Sstevel@tonic-gate#	"lines resulting in those lines which need to be"
42*7c478bd9Sstevel@tonic-gate#	"deleted or added from loginlog"
43*7c478bd9Sstevel@tonic-gate#	"line 3 - result of sort will be a file with 2 copies"
44*7c478bd9Sstevel@tonic-gate#	"of lines to delete and 1 copy of lines that are "
45*7c478bd9Sstevel@tonic-gate#	"valid; use uniq to remove duplicate lines"
46*7c478bd9Sstevel@tonic-gategetent passwd | sed "s/\([^:]*\).*/00-00-00  \1/" |\
47*7c478bd9Sstevel@tonic-gatesort +1 - sum/loginlog | uniq -u +10 |\
48*7c478bd9Sstevel@tonic-gatesort +1 - sum/loginlog |uniq -u > sum/tmploginlog
49*7c478bd9Sstevel@tonic-gatecp sum/tmploginlog sum/loginlog
50*7c478bd9Sstevel@tonic-gate#	"update loginlog"
51*7c478bd9Sstevel@tonic-gate_d="`date +%y-%m-%d`"
52*7c478bd9Sstevel@tonic-gate_day=`date +%m%d`
53*7c478bd9Sstevel@tonic-gate#	"lines 1 and 2 - remove everything from the total"
54*7c478bd9Sstevel@tonic-gate#	"acctng records with connect info except login"
55*7c478bd9Sstevel@tonic-gate#	"name and adds the date"
56*7c478bd9Sstevel@tonic-gate#	"line 3 - sorts in reverse order by login name; gets"
57*7c478bd9Sstevel@tonic-gate#	"1st occurrence of each login name and resorts by date"
58*7c478bd9Sstevel@tonic-gateacctmerg -a < nite/ctacct.$_day | \
59*7c478bd9Sstevel@tonic-gatesed -e "s/^[^ 	]*[ 	]\([^ 	]*\)[ 	].*/$_d  \1/" | \
60*7c478bd9Sstevel@tonic-gatenawk	'/^00-00-00/ {
61*7c478bd9Sstevel@tonic-gate                $0 = "00" $0
62*7c478bd9Sstevel@tonic-gate        }
63*7c478bd9Sstevel@tonic-gate	/^[0-9][0-9]-/ {
64*7c478bd9Sstevel@tonic-gate                d=substr($0,1,2);
65*7c478bd9Sstevel@tonic-gate                if (d<=68) {
66*7c478bd9Sstevel@tonic-gate                        $0 = "20" $0
67*7c478bd9Sstevel@tonic-gate                } else {
68*7c478bd9Sstevel@tonic-gate                        $0 = "19" $0
69*7c478bd9Sstevel@tonic-gate                }
70*7c478bd9Sstevel@tonic-gate        }
71*7c478bd9Sstevel@tonic-gate        { print }' - sum/loginlog | \
72*7c478bd9Sstevel@tonic-gatesort -r +1 | uniq +10 | sort | \
73*7c478bd9Sstevel@tonic-gatenawk	'/^[0-9][0-9][0-9][0-9]-/ {
74*7c478bd9Sstevel@tonic-gate	$0 = substr($0,3)
75*7c478bd9Sstevel@tonic-gate    }
76*7c478bd9Sstevel@tonic-gate    { print }' > sum/tmploginlog
77*7c478bd9Sstevel@tonic-gatecp sum/tmploginlog sum/loginlog
78*7c478bd9Sstevel@tonic-gaterm -f sum/tmploginlog
79